package avicit.cbb.techclass.tabledefine.commtablemanager.action.service.impl;

import avicit.cbb.businessclass.fondsmanage.action.DBConnectionCustomManager;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsDb;
import avicit.cbb.fondsmanage.service.CbbFondsDbIntfsService;
import avicit.cbb.tabledefine.service.CommTableManagerIntfsService;
import avicit.cbb.techclass.billdefine.action.service.BillDefineManagerService;
import avicit.cbb.techclass.billdefine.domain.CbbTabForm;
import avicit.cbb.techclass.billdefine.domain.CbbTabFormConfig;
import avicit.cbb.techclass.billdefine.domain.CbbTabFormNode;
import avicit.cbb.techclass.billdefine.service.BillDefineManagerService;
import avicit.cbb.techclass.tabledefine.cbbtabcolcodetl.dto.CbbTabColCodeTlDTO;
import avicit.cbb.techclass.tabledefine.cbbtabcolcodetl.service.CbbTabColCodeTlService;
import avicit.cbb.techclass.tabledefine.cbbtabcolumnstl.dao.CbbTabColumnsTlDao;
import avicit.cbb.techclass.tabledefine.cbbtabcolumnstl.dto.CbbTabColumnsTlDTO;
import avicit.cbb.techclass.tabledefine.cbbtabcolumnstl.service.CbbTabColumnsTlService;
import avicit.cbb.techclass.tabledefine.cbbtempletcodetl.service.CbbTempletCodeTlService;
import avicit.cbb.techclass.tabledefine.cbbtempletfieldtl.service.CbbTempletFieldTlService;
import avicit.cbb.techclass.tabledefine.commtablemanager.dao.CommTableManagerDao;
import avicit.cbb.techclass.tabledefine.commtablemanager.domain.*;
import avicit.cbb.techclass.tabledefine.commtablemanager.action.service.CommTableManagerService;
import avicit.cbb.techclass.tabledefine.commtempletmanager.domain.CbbTempletCode;
import avicit.cbb.techclass.tabledefine.commtempletmanager.domain.CbbTempletField;
import avicit.im.lantop.basic.archiveclassmanager.domain.LantopArchiveClass;
import avicit.im.lantop.basic.fieldmapset.dao.LantopFieldMapSetManagerDao;
import avicit.im.lantop.basic.fieldmapset.domain.LantopFieldRelateSet;
import avicit.im.lantop.basic.fieldmapset.domain.LantopFieldRelateSetItem;
import avicit.platform6.api.sysmenu.dto.SysMenu;
import avicit.platform6.api.sysmenu.dto.SysMenuTl;
import avicit.platform6.api.sysresource.dto.SysResource;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.Pinyin4jUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.rest.client.RestClient;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.rest.msg.ResponseStatus;
import avicit.platform6.core.service.ServiceBase;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.modules.system.centralizedauthorization.domain.SysAccesscontrol;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import avicit.platform6.modules.system.sysorguser.sysrole.domain.SysRole;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.ws.rs.core.GenericType;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>
 * 金航数码科技有限责任公司
 * </p>
 * <p>
 * 作者：朱锋
 * </p>
 * <p>
 * 邮箱：zhufeng@avicit.com
 * </p>
 * <p>
 * 创建时间： 2014-9-30 上午11:11:11
 * </p>
 * <p>
 * 类说明：库表实现类
 * </p>
 * <p>
 * 修改记录：
 * </p>
 */
@SuppressWarnings("unchecked")
@Service
public class CommTableManagerServiceImpl extends ServiceBase implements CommTableManagerService {

	@Autowired(required = false)
	private JdbcAvicit jdbcAvicit;
	@Autowired(required = true)
	private JdbcTemplate jdbcTemplate;
	@Autowired(required = true)
	CommTableManagerDao commTableManagerDao;
	@Autowired(required = true)
	private CbbTabColumnsTlDao cbbTabColumnsTlDao;
	@Autowired(required = true)
	BillDefineManagerService billDefineManagerService;
	@Autowired(required = true)
	CbbFondsDbIntfsService cbbFondsDbIntfsService;
	// 多语言信息需要调用的service
	@Autowired(required = true)
	CbbTabColumnsTlService cbbTabColumnsTlService;
	@Autowired(required = true)
	CbbTabColCodeTlService cbbTabColCodeTlService;
	@Autowired(required = true)
	CbbTempletFieldTlService cbbTempletFieldTlService;
	@Autowired(required = true)
	CbbTempletCodeTlService cbbTempletCodeTlService;
	@Autowired(required = true)
	LantopFieldMapSetManagerDao lantopFieldMapSetManagerDao;

	@Autowired(required = true)
	private CommTableManagerIntfsService commTableManagerIntfsService;
	// 解析2003文件后的数据
	private Map<String, Vector<Vector<String>>> sheetXls = new HashMap<String, Vector<Vector<String>>>();
	// 解析2007文件后的数据
	private Map<String, Vector<Vector<String>>> sheetXlsx = new HashMap<String, Vector<Vector<String>>>();
	private HSSFWorkbook workbook;
	private HSSFSheet sheet;
	// 创建一行
	private HSSFRow row = null;
	private HSSFCell cell = null;
	private HSSFCellStyle stringstyle;
	private HSSFCellStyle headStyle;

	@Override
	public void delete(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void insert(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	/**
	 * 更新列信息
	 *
	 * @param cbbTabColumnsArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateCbbTabColumns(CbbTabColumns[] cbbTabColumnsArray, String sysId, String nodeId, String nodeName, String tableName, boolean isTrue, Map<String, Object> param) throws Exception {
		String languageCode = param.get("languageCode").toString();
		String orgId = param.get("orgId").toString();
		param.remove("languageCode");
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String nameParam = ""; // 级联删除字段对应设置参数，字段名，多个用英文逗号分割
		String tableIdParam = ""; // 级联删除字段对应设置参数，表ID
		CbbTabColumns newBean = null;
		try {
			for (int i = 0; i < cbbTabColumnsArray.length; i++) {
				CbbTabColumns cbbTabColumns = cbbTabColumnsArray[i];
				// 更新基本字段信息
				CbbTabColumns oldBean = getCbbTabColumnsById(cbbTabColumns.getId());
				String oldColName = oldBean.getColName();// 数据库中的列名
				String oldType = oldBean.getColType();// 数据库中的列类型
				BigDecimal oldLength = oldBean.getColLength();// 数据库中的列长度
				BigDecimal oldDecimal = cbbTabColumns.getColDecimal();// 数据库中的列小数位数
				String colName = cbbTabColumns.getColName();// 提交的列名
				String colType = cbbTabColumns.getColType();// 提交的列类型
				BigDecimal colLength = cbbTabColumns.getColLength();// 提交的列长度
				BigDecimal colDecimal = cbbTabColumns.getColDecimal();// 提交的列小数位数
				String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
				tableIdParam = tableId;
				hibernateDao.evict(oldBean);
				newBean = new CbbTabColumns();
				PojoUtil.copyProperties(newBean, oldBean, true);
				// 删除字段的配置信息（组合项或统计生成）
				PojoUtil.copyProperties(newBean, cbbTabColumns, true);
				SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
				if (colLength == null) {
					newBean.setColLength(null);
				}
				if (colDecimal == null) {
					newBean.setColDecimal(null);
				}
				if (isTrue) {

					boolean flag = checkColIsMust(tableId);
					// 查询SYSID及组织ID，获取所对应的用户名
					List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
					String dbUser = "";// 用户名
					if (listConn.size() > 0) {
						Map<String, Object> connmap = listConn.get(0);
						dbUser = String.valueOf(connmap.get("DB_USER"));
					} else {
						throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
					}
					// if (flag || !oldLength.equals(colLength)) {
					// SanXiaFiles update by huangjian 使用equest异常 改回原来的方式
					if (flag || oldLength != colLength) {
						if (!oldColName.equals(colName)) {
							// 更改列名
							String updateColName = "ALTER TABLE " + dbUser + "." + tableName + " RENAME COLUMN " + oldColName + " TO " + colName;
							this.jdbcAvicit.getJdbcTemplate().execute(updateColName);
							SysLogUtil.log("库结构定义模块", "删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
							this.jdbcAvicit.getJdbcTemplate().execute("commit");
						}
						/*
						 * if (!colType.equals(oldType) || !oldLength.equals(colLength) || !oldDecimal.equals(colDecimal)) {
						 */
						// SanXiaFiles update by huangjian 使用equest异常 改回原来的方式
						if (!colType.equals(oldType) || oldLength != colLength || oldDecimal != colDecimal) {
							// 判断列类型
							if (colType.equals("string")) {
								colType = "VARCHAR2(" + (null == colLength ? "128" : colLength) + ")";
							} else if (colType.equals("integer")) {
								colType = "NUMBER" + "(" + (null == colLength ? "16" : colLength) + ")";
							} else if (colType.equals("date")) {
								colType = "DATE";
							} else if (colType.equals("float")) {
								colType = "NUMBER" + "(" + (null == colLength ? "16" : colLength) + "," + (null == colDecimal ? "6" : colDecimal) + ")";
							} else if (colType.equals("blob")) {
								colType = "BLOB";
							} else if (colType.equals("clob")) {
								colType = "CLOB";
							}
							// 更改类型
							String updateColName = "ALTER TABLE " + dbUser + "." + tableName + " MODIFY " + colName + " " + colType;
							this.jdbcAvicit.getJdbcTemplate().execute(updateColName);
							SysLogUtil.log("库结构定义模块", "修改记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
							this.jdbcAvicit.getJdbcTemplate().execute("commit");
						}
					}
					// 更新列注释
					String updateSql = "COMMENT ON COLUMN " + dbUser + "." + tableName + "." + cbbTabColumnsArray[i].getColName() + "\n" + "  is '" + cbbTabColumnsArray[i].getColLabel() + "'";
					this.jdbcAvicit.getJdbcTemplate().execute(updateSql);
					SysLogUtil.log("库结构定义模块", "修改记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
					this.jdbcAvicit.getJdbcTemplate().execute("commit");
					SysLogUtil.log("库结构定义模块", "更新实体表字段记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
				}
				// 1、同步节点著录定义信息
				// Map<String, Object> tabNodeRecordParam = new HashMap<String,
				// Object>();
				// tabNodeRecordParam.put("sysId", sysId);
				// tabNodeRecordParam.put("orgId", param.get("orgId"));
				// tabNodeRecordParam.put("deptId", param.get("deptId"));
				// tabNodeRecordParam.put("tableId", tableId);
				// tabNodeRecordParam.put("obj", newBean);
				// this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
				// 构造同步初始化字段对应设置配置信息参数
				if ("N".equals(newBean.getColIsDisplay())) {
					nameParam = nameParam + "," + newBean.getColName();
				}
				// 2、同步表单配置信息
				if ("N".equals(newBean.getColIsDisplay())) {
					// 删除表单配置信息
					String deleteFormConfigSql = "DELETE FROM CBB_TAB_FORM_CONFIG T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteFormConfigSql);
					SysLogUtil.log("库结构定义模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
				} else {
					// 添加表单配置信息
					List<String> formIdList = getFormIdByTableIdByFormConfig(sysId, tableId);// formId
					/*
					 * String formId = ""; if (formIdList.size() > 0) { formId = formIdList.get(0); }
					 */
					// SanXiaFiles update by huangjian 支持多个表单的修改
					if (formIdList.size() > 0) {
						for (String formId : formIdList) {
							if (!"".equals(formId) && !"null".equalsIgnoreCase(formId)) {
								// 根据formId和columnId判断该字段是否已经存在配置信息
								boolean hasConfig = billDefineManagerService.getformConfigByFormIdAndColId(formId, cbbTabColumns.getId());
								if (!hasConfig) {
									String formConfigId = ComUtil.getId();
									CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
									cbbTabFormConfig.setId(formConfigId);
									cbbTabFormConfig.setFormId(formId);
									cbbTabFormConfig.setColumnId(cbbTabColumns.getId());
									BigDecimal formVertical = new BigDecimal(1);
									cbbTabFormConfig.setFormVertical(formVertical);
									BigDecimal formHorizontal = new BigDecimal(1);
									cbbTabFormConfig.setFormHorizontal(formHorizontal);
									cbbTabFormConfig.setOrgId(cbbTabColumns.getOrgId());
									cbbTabFormConfig.setDeptId(cbbTabColumns.getDeptId());
									cbbTabFormConfig.setSysId(sysId);
									cbbTabFormConfig.setAttribute11(cbbTabColumns.getColOrder());
									cbbTabFormConfig.setAttribute12(cbbTabColumns.getAttribute11());
									PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
									hibernateDao.save(cbbTabFormConfig);
									SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
								}// else{//如果存在表单和列的信息 则修改 2019-08-20 以表单信息为主
									// SanXiaFiles update by huangjian 修改表单的信息
									// start
									// 1.是否必著 ATTRIBUTE_01
									// 2.表单顺序 ATTRIBUTE_11
									// 3.表格顺序 ATTRIBUTE_12
								/*
								 * try { Map<String, Object> formConfigInfo= getformConfigByFormIdAndColId (formId,cbbTabColumns .getId());//获得formConfigInfo信息 if(null !=
								 * formConfigInfo){ String formConfigId = (String) formConfigInfo.get("ID"); CbbTabFormConfig cbbTabFormConfig = billDefineManagerService
								 * .getcbbTabFormConfigById(formConfigId); cbbTabFormConfig .setAttribute01(cbbTabColumns. getColIsMust()); cbbTabFormConfig.setAttribute11
								 * (cbbTabColumns.getColOrder()); cbbTabFormConfig .setAttribute12(cbbTabColumns. getAttribute11()); cbbTabFormConfig.setRemark(
								 * cbbTabColumns.getRemark());//备注 billDefineManagerService .updateCbbTabForm(cbbTabFormConfig); } } catch (Exception e) { e.printStackTrace(); }
								 */
								// SanXiaFiles update by huangjian 修改表单的信息 end
								// }
							}
						}

					}

				}
				PojoUtil.setSysProperties(newBean, OpType.update);
				hibernateDao.update(newBean);

				CbbTabColumnsTlDTO cbbTabColumnsTlDTO = new CbbTabColumnsTlDTO();
				cbbTabColumnsTlDTO.setCbbTabColumnsId(cbbTabColumns.getId());
				List<CbbTabColumnsTlDTO> cbbTabColumnsTlDTOList = cbbTabColumnsTlDao.searchCbbTabColumnsTl(cbbTabColumnsTlDTO);
				for (CbbTabColumnsTlDTO dto : cbbTabColumnsTlDTOList) {
					String sysLanguageCode = dto.getSysLanguageCode();
					if (null == languageCode || "".equals(languageCode) || languageCode.equals("zh_CN")) {
						if (sysLanguageCode.equals("zh_CN")) {
							dto.setColumnsShowName(newBean.getColLabel());
							cbbTabColumnsTlDao.updateCbbTabColumnsTlSensitive(dto);
						}
					} else {
						if (sysLanguageCode.equals("en")) {
							dto.setColumnsShowName(newBean.getColLabel());
							cbbTabColumnsTlDao.updateCbbTabColumnsTlSensitive(dto);
						}
					}
				}
			}
			// 同步字段对应设置信息
			if (!"".equals(nameParam)) {
				nameParam = nameParam.substring(1);
			}
			Map<String, String> relateSetParam = new HashMap<String, String>();
			relateSetParam.put("tableId", tableIdParam);
			relateSetParam.put("orgId", (String) param.get("orgId"));
			relateSetParam.put("colName", nameParam);
			// 调用rest服务，删除字段对应设置配置信息并更新档案大视图
//			FieldMapSetRestClient fieldMapSetRestClient = new FieldMapSetRestClient("/api/im/lantop/basic/fieldmapset");
//			RestClient.doPost(fieldMapSetRestClient.getRestUrl("/updateConfig/v1"), relateSetParam, new GenericType<ResponseMsg<Integer>>() {
//			});
			RestClient.doPost("/updateConfig/v1\")",relateSetParam,new GenericType<ResponseMsg<Integer>>() {
			});
			/*
			 * if (responseMsg.getRetCode().equals(ResponseStatus.HTTP_OK)) { } else { throw new RuntimeException(responseMsg.getErrorDesc()); }
			 */
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e);
		}
	}

	/**
	 * 更新节点著录信息
	 *
	 * @param cbbTabColumnsArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateCbbTabRecord(List<CbbTabColumns> list, String sysId, String tabNodeId, String orgId, String deptId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		for (int i = 0; i < list.size(); i++) {
			// 更新基本字段信息
			CbbTabColumns cbbTabColumns = list.get(i);
			try {
				String recordId = this.getCbbTabNodeRecordIdByColIdAndTableNodeId(cbbTabColumns.getId(), tabNodeId);// 获取recordId
				if (!"".equals(recordId)) {
					// 如果存在此列信息，那么更新节点著录信息表信息
					CbbTabNodeRecord oldBean = this.getCbbTabNodeRecordById(recordId);
					CbbTabNodeRecord newBean = new CbbTabNodeRecord();
					PojoUtil.copyProperties(newBean, oldBean, true);
					newBean.setColIsVisible(cbbTabColumns.getColIsVisible());
					newBean.setColIsTabVisible(cbbTabColumns.getColIsTabVisible());
					newBean.setColIsDetail(cbbTabColumns.getColIsDetail());
					newBean.setColIsSearch(cbbTabColumns.getColIsSearch());
					newBean.setColOrder(cbbTabColumns.getColOrder());
					newBean.setOrgId(orgId);
					newBean.setSysId(sysId);
					newBean.setDeptId(deptId);
					SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
					PojoUtil.setSysProperties(newBean, OpType.update);
					hibernateDao.merge(newBean);
				} else {
					// 如果不存在此列信息，那么新增节点著录信息表信息
					CbbTabNodeRecord cbbTabNodeRecord = new CbbTabNodeRecord();
					cbbTabNodeRecord.setId(ComUtil.getId());
					cbbTabNodeRecord.setTabNodeId(tabNodeId);
					cbbTabNodeRecord.setColumnId(cbbTabColumns.getId());
					cbbTabNodeRecord.setColIsVisible(cbbTabColumns.getColIsVisible());
					cbbTabNodeRecord.setColIsTabVisible(cbbTabColumns.getColIsTabVisible());
					cbbTabNodeRecord.setColIsDetail(cbbTabColumns.getColIsDetail());
					cbbTabNodeRecord.setColIsSearch(cbbTabColumns.getColIsSearch());
					cbbTabNodeRecord.setColOrder(cbbTabColumns.getColOrder());
					cbbTabNodeRecord.setOrgId(orgId);
					cbbTabNodeRecord.setSysId(sysId);
					cbbTabNodeRecord.setDeptId(deptId);
					cbbTabNodeRecord.setTableId(tableId);
					PojoUtil.setSysProperties(cbbTabNodeRecord, OpType.insert);
					hibernateDao.save(cbbTabNodeRecord);
					SysLogUtil.log(cbbTabNodeRecord, null, OpType.insert, OpResult.success);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 根据列信息ID获取节点著录信息
	 *
	 * @param id
	 * @return CbbTabNodeRecord
	 * @throws
	 * @author 朱锋
	 */
	public CbbTabNodeRecord getCbbTabNodeRecordById(String id) {
		CbbTabNodeRecord h = (CbbTabNodeRecord) hibernateDao.getSession().get(CbbTabNodeRecord.class, id);
		return h;
	}

	/**
	 * 根据colId及TableNodeId获取节点著录ID
	 *
	 * @param cid
	 * @param TableNodeId
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	public String getCbbTabNodeRecordIdByColIdAndTableNodeId(String cid, String tableNodeId) {
		String recordId = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID\n");
		sbSql.append("  FROM CBB_TAB_NODE_RECORD T\n");
		sbSql.append(" WHERE T.TAB_NODE_ID = '" + tableNodeId + "'\n");
		sbSql.append("   AND T.COLUMN_ID = '" + cid + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList.size() != 0) {
			recordId = String.valueOf(objList.get(0));
		}
		return recordId;
	}

	/**
	 * 更新代码维护信息
	 *
	 * @param cbbTabColCodeArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateCbbTabColCode(List<CbbTabColCode> cbbTabColCodeArray, String sysId, String nodeId, String nodeName) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		for (int i = 0; i < cbbTabColCodeArray.size(); i++) {
			// 更新基本字段信息
			CbbTabColCode oldBean = getCbbTabColCodeById(cbbTabColCodeArray.get(i).getId());
			hibernateDao.evict(oldBean);
			CbbTabColCode newBean = new CbbTabColCode();
			PojoUtil.copyProperties(newBean, oldBean, true);
			PojoUtil.copyProperties(newBean, cbbTabColCodeArray.get(i), true);
			SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
			PojoUtil.setSysProperties(newBean, OpType.update);
			hibernateDao.update(newBean);
		}
	}

	/**
	 * 代码维护中更新列信息
	 *
	 * @param cbbTabColumnsArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateCbbTabColumnsTemp(CbbTabColumns[] cbbTabColumnsArray, String sysId, String nodeId, String nodeName) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		for (int i = 0; i < cbbTabColumnsArray.length; i++) {
			// 更新基本字段信息
			CbbTabColumns oldBean = this.getCbbTabColumnsById(cbbTabColumnsArray[i].getId());
			hibernateDao.evict(oldBean);
			CbbTabColumns newBean = new CbbTabColumns();
			PojoUtil.copyProperties(newBean, oldBean, true);
			/*
			 * String colDropdownTypeNew = cbbTabColumnsArray[i] .getColDropdownType(); String colDropdownTypeOld = cbbTabColumnsTemp.getColDropdownType();
			 */
			PojoUtil.copyProperties(newBean, cbbTabColumnsArray[i], true);
			SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
			PojoUtil.setSysProperties(newBean, OpType.update);
			/*
			 * if (!colDropdownTypeOld.equals(colDropdownTypeNew)) { // 更改了下拉类型 // 清除配置旧信息COL_GENE_METHOD--0；COL_GENE_METHOD_RULE--"" cbbTabColumnsTemp.setColGeneMethod("0");
			 * cbbTabColumnsTemp.setColGeneMethodRule(""); }
			 */
			hibernateDao.update(newBean);
		}
	}

	/**
	 * 更新字段排序信息
	 *
	 * @param cbbTabColSort
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateCbbTabColSort(BeanBase beanBase) throws Exception {
		CbbTabColSort cbbTabColSort = (CbbTabColSort) beanBase;
		if (cbbTabColSort == null) {
			throw new DaoException("对象转换为cbbTabColSort对象为空！");
		}
		CbbTabColSort oldBean = getCbbTabColSortById(cbbTabColSort.getId());
		// 更新基本字段信息
		hibernateDao.evict(oldBean);
		CbbTabColSort newBean = new CbbTabColSort();
		PojoUtil.copyProperties(newBean, oldBean, true);
		PojoUtil.copyProperties(newBean, cbbTabColSort, true);
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		hibernateDao.update(newBean);
	}

	/**
	 * 更新分类检索信息
	 *
	 * @param cbbTabColSort
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateCbbTabColSearch(CbbTabColSearch cbbTabColSearch) throws Exception {
		CbbTabColSearch oldBean = getCbbTabColSearchById(cbbTabColSearch.getId());
		// 更新基本字段信息
		hibernateDao.evict(oldBean);
		CbbTabColSearch newBean = new CbbTabColSearch();
		PojoUtil.copyProperties(newBean, oldBean, true);
		PojoUtil.copyProperties(newBean, cbbTabColSearch, true);
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		hibernateDao.update(newBean);
	}

	/**
	 * 新增列各种信息
	 *
	 * @param cbbTabColumnsArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertCbbTabColumns(CbbTabColumns[] cbbTabColumnsArray, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId, String loginUserId, String loginIp, String isTrueTable) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		for (int i = 0; i < cbbTabColumnsArray.length; i++) {
			CbbTabColumns cbbTabColumns = cbbTabColumnsArray[i];
			// 实体表已经存在的情况下,新增字段都是可为空的
			if (cbbTabColumns == null) {
				throw new Exception("对象转换为cbbTabColumns对象出错！");
			}
			// 查询tableId
			String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
			String cid = ComUtil.getId();
			cbbTabColumns.setId(cid);
			cbbTabColumns.setTableId(tableId);
			cbbTabColumns.setSysId(sysId);
			cbbTabColumns.setOrgId(orgId);
			cbbTabColumns.setDeptId(deptId);
			cbbTabColumns.setCreatedBy(loginUserId);
			cbbTabColumns.setLastUpdatedBy(loginUserId);
			cbbTabColumns.setLastUpdateIp(loginIp);
			cbbTabColumns.setColIsVisible("Y");
			cbbTabColumns.setColIsSearch("N");
			cbbTabColumns.setColIsEdit("Y");
			cbbTabColumns.setColIsTabVisible("N");
			cbbTabColumns.setColIsDetail("Y");
			cbbTabColumns.setColDropdownType("0");
			cbbTabColumns.setColGeneMethod("0");
			cbbTabColumns.setColShowFormat("0");
			cbbTabColumns.setColIsComplement("N");
			// 实体表已经存在的情况下,新增字段都是可为空的
			insertCbbTabColumus(cbbTabColumns);
			// 查询SYSID及组织ID，获取所对应的用户名
			List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
			String dbUser = "";// 用户名
			if (listConn.size() > 0) {
				Map<String, Object> connmap = listConn.get(0);
				dbUser = String.valueOf(connmap.get("DB_USER"));
			} else {
				throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
			}
			// 给实体表新增字段
			String colType = cbbTabColumns.getColType();
			// 判断列类型
			BigDecimal colLength = cbbTabColumns.getColLength();
			BigDecimal colDecimal = cbbTabColumns.getColDecimal();
			if (colType.equals("string")) {
				colType = "VARCHAR2(" + (null == colLength ? "128" : colLength) + ")";
			} else if (colType.equals("integer")) {
				colType = "NUMBER" + "(" + (null == colLength ? "16" : colLength) + ")";
			} else if (colType.equals("date")) {
				colType = "DATE";
			} else if (colType.equals("float")) {
				colType = "NUMBER" + "(" + (null == colLength ? "16" : colLength) + "," + (null == colDecimal ? "6" : colDecimal) + ")";
			} else if (colType.equals("blob")) {
				colType = "BLOB";
			} else if (colType.equals("clob")) {
				colType = "CLOB";
			}
			// 虚拟表不进行实体表维护
			if (!"N".equals(isTrueTable)) {
				try {
					String addCol = "ALTER TABLE " + dbUser + "." + tableName + " ADD " + cbbTabColumns.getColName() + " " + colType;
					this.jdbcAvicit.getJdbcTemplate().execute(addCol);
					this.jdbcAvicit.getJdbcTemplate().execute("commit");
					SysLogUtil.log("库结构定义模块", "修改记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
					// 给此字段增加注释
					addCol = "COMMENT ON COLUMN " + tableName + "." + cbbTabColumns.getColName() + "\n" + "  is '" + cbbTabColumns.getColLabel() + "'";
					this.jdbcAvicit.getJdbcTemplate().execute(addCol);
					this.jdbcAvicit.getJdbcTemplate().execute("commit");
					SysLogUtil.log("库结构定义模块", "新增实体表列记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
				} catch (Exception e) {
					e.printStackTrace();
					// 回滚添加列的数据
					CbbTabColumns cbbTabColumnsTemp = new CbbTabColumns();
					cbbTabColumnsTemp = getCbbTabColumnsById(cid);
					String mes = "字段【" + cbbTabColumns.getColLabel() + "】已经存在，不能重复添加！";
					deleteCbbTabColumnsById(cbbTabColumnsTemp);
					throw new Exception(mes);
				}
			}
			// 给表单配置信息表添加数据
			List<String> formIdList = getFormIdByTableIdByFormConfig(sysId, tableId);// formId
			// SanXiaFiles update by huangjian 2019-08-20 支持多个表单设置
			/*
			 * String formId = ""; if (formIdList.size() > 0) { formId = formIdList.get(0); }
			 */
			if (formIdList.size() > 0) {
				for (String formId : formIdList) {
					if (!"".equals(formId) && !"null".equalsIgnoreCase(formId)) {
						// 根据formId和columnId判断该字段是否已经存在配置信息
						boolean hasConfig = billDefineManagerService.getformConfigByFormIdAndColId(formId, cid);
						if (!hasConfig) {
							String formConfigId = ComUtil.getId();
							CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
							cbbTabFormConfig.setId(formConfigId);
							cbbTabFormConfig.setFormId(formId);
							cbbTabFormConfig.setColumnId(cid);
							BigDecimal formVertical = new BigDecimal(1);
							cbbTabFormConfig.setFormVertical(formVertical);
							BigDecimal formHorizontal = new BigDecimal(1);
							cbbTabFormConfig.setFormHorizontal(formHorizontal);
							cbbTabFormConfig.setOrgId(orgId);
							cbbTabFormConfig.setDeptId(deptId);
							cbbTabFormConfig.setSysId(sysId);
							cbbTabFormConfig.setAttribute11(cbbTabColumns.getColOrder());
							cbbTabFormConfig.setAttribute12(cbbTabColumns.getAttribute11());
							PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
							hibernateDao.save(cbbTabFormConfig);
							SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
						}
					}
				}
			}

			// // 2同步节点著录定义配置信息
			// Map<String, Object> tabNodeRecordParam = new HashMap<String,
			// Object>();
			// tabNodeRecordParam.put("sysId", sysId);
			// tabNodeRecordParam.put("orgId", orgId);
			// tabNodeRecordParam.put("deptId", deptId);
			// tabNodeRecordParam.put("tableId", tableId);
			// tabNodeRecordParam.put("obj", cbbTabColumns);
			// this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
		}
	}

	/**
	 * 向CBB_TABLES插入记录
	 *
	 * @param tid
	 * @param tableName
	 * @param tableTitle
	 * @param sysId
	 * @param orgId
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	public void insertCbbTables(String tid, String tableName, String tableTitle, String sysId, String orgId, String deptId, String loginUserId, String loginIp) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		try {
			String sqlTable = "INSERT INTO CBB_TABLES\n" + "VALUES\n" + "  ('" + tid + "',\n" + "   '" + tableName + "',\n" + "   '" + tableTitle + "',\n" + "   'Y',\n" + "   '',\n" + "   '" + orgId + "',\n" + "   '" + deptId + "',\n" + "   '" + sysId + "',\n" + "   '',\n"
					+ "   '',\n" + "   SYSDATE,\n" + "   '" + loginUserId + "',\n" + "   SYSDATE,\n" + "   '" + loginUserId + "',\n" + "   '" + loginIp + "',\n" + "   1,\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n"
					+ "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '')";
			this.jdbcAvicit.getJdbcTemplate().execute(sqlTable);
			this.jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "插入表记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 向CBB_TAB_COLUMNS插入记录
	 *
	 * @param cbbTabColumns
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	public void insertCbbTabColumus(CbbTabColumns cbbTabColumns) {
		String colLength = String.valueOf(cbbTabColumns.getColLength());
		String colType = cbbTabColumns.getColType();
		String colDecimal = String.valueOf(cbbTabColumns.getColDecimal());
		if ("string".equals(colType)) { // 字符串
			if ("null".equals(colLength)) {
				colLength = "30";
			}
		} else if ("integer".equals(colType)) { // 整型
			if ("null".equals(colLength)) {
				colLength = "16";
			}
		} else if ("float".equals(colType)) { // 浮点型
			if ("null".equals(colLength)) {
				colLength = "16";
			}
			if ("null".equals(colDecimal)) {
				colDecimal = "2";
			}
		}
		try {
			String sqlcol = "INSERT INTO CBB_TAB_COLUMNS\n" + "VALUES\n" + "  ('" + cbbTabColumns.getId() + "',\n" + "   '" + cbbTabColumns.getTableId() + "',\n" + "   '" + cbbTabColumns.getColName() + "',\n" + "   '" + cbbTabColumns.getColLabel() + "',\n" + "   '"
					+ cbbTabColumns.getColType() + "',\n" + "   " + colLength + ",\n" + "   " + colDecimal + ",\n" + "   '" + cbbTabColumns.getColIsSys() + "',\n" + "   " + cbbTabColumns.getColOrder() + ",\n" + "   '" + cbbTabColumns.getColIsMust() + "',\n" + "   '"
					+ cbbTabColumns.getColIsVisible() + "',\n" + "   '" + cbbTabColumns.getColIsSearch() + "',\n" + "   '" + cbbTabColumns.getColIsEdit() + "',\n" + "   '" + cbbTabColumns.getColIsTabVisible() + "',\n" + "   '" + cbbTabColumns.getColIsDetail() + "',\n" + "   '"
					+ cbbTabColumns.getColDropdownType() + "',\n" + "   '" + cbbTabColumns.getColGeneMethod() + "',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '" + (cbbTabColumns.getRemark() == null ? "" : cbbTabColumns.getRemark()) + "',\n" + "   '"
					+ cbbTabColumns.getOrgId() + "',\n" + "   '" + cbbTabColumns.getDeptId() + "',\n" + "   '" + cbbTabColumns.getSysId() + "',\n" + "   '',\n" + "   '',\n" + "   SYSDATE,\n" + "   '" + cbbTabColumns.getLastUpdatedBy() + "',\n" + "   SYSDATE,\n" + "   '"
					+ cbbTabColumns.getCreatedBy() + "',\n" + "   '" + cbbTabColumns.getLastUpdateIp() + "',\n" + "   1,\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n"
					+ "   " + cbbTabColumns.getAttribute11() + ",\n" + "   '',\n" + "   '',\n" + "   '" + (cbbTabColumns.getColShowFormat() == null ? "" : cbbTabColumns.getColShowFormat()) + "',\n" + "   '',\n" + "   '"
					+ (cbbTabColumns.getColIsDisplay() == null ? "" : cbbTabColumns.getColIsDisplay()) + "','" + cbbTabColumns.getColIsComplement() + "'," + cbbTabColumns.getColComplementNum() + ",'" + cbbTabColumns.getColGeneMethodRuleText() + "')";
			this.jdbcAvicit.getJdbcTemplate().execute(sqlcol);
			this.jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "插入列记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 创建表与节点关联关系 参数：系统标识ID，节点ID，库表ID
	 *
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void createCbbTabNode(String sysId, String nodeId, String tid, String orgId, String deptId, String loginUserId, String loginIp) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String nid = ComUtil.getId();
		// 取CBB_TAB_NODE该TABLE_ID,NODE_ID,SYS_ID下的最大排序值
		int tnum = selectMaxSort(nodeId, sysId) + 1;
		BigDecimal sortOrder = new BigDecimal(tnum);
		try {
			String sqlNode = "INSERT INTO CBB_TAB_NODE\n" + "VALUES\n" + "  ('" + nid + "',\n" + "   '" + tid + "',\n" + "   '" + nodeId + "',\n" + "   " + sortOrder + ",\n" + "   '',\n" + "   '" + orgId + "',\n" + "   '" + deptId + "',\n" + "   '" + sysId + "',\n" + "   '',\n"
					+ "   '',\n" + "   SYSDATE,\n" + "   '" + loginUserId + "',\n" + "   SYSDATE,\n" + "   '" + loginUserId + "',\n" + "   '" + loginIp + "',\n" + "   1,\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n"
					+ "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '',\n" + "   '')";
			this.jdbcAvicit.getJdbcTemplate().execute(sqlNode);
			this.jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "插入表与节点关系记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查询以存在编号数量
	 *
	 * @param textpinyin
	 * @return
	 * @throws Exception
	 *             int
	 * @throws
	 * @author 朱锋
	 */
	public int getSumTableCount(String textpinyin) throws Exception {
		int q = 0;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*) FROM CBB_TABLES T WHERE T.TABLE_NAME LIKE '" + textpinyin + "%'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		q = Integer.parseInt(String.valueOf(objList.get(0)));
		return q;

	}

	/**
	 * 生成动态表
	 *
	 * @param tableId
	 * @param sysId
	 * @throws DaoException
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertdbTable(String tableId, String sysId, String orgId) throws DaoException {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		ArrayList<Object> params = new ArrayList<Object>();
		try {
			// 查询表名，表注释
			String sqlt = "select t.table_name,t.table_title from CBB_TABLES t where t.id = '" + tableId + "'";
			List<Object[]> listt = hibernateDao.findBySQL(sqlt);
			Object[] objt = listt.get(0);
			String tableName = String.valueOf(objt[0]);// 表名
			String tableTitle = String.valueOf(objt[1]);// 表注释
			// 查询TEMPLETID
			String templetId = getInitTemplet(sysId, orgId);
			// 查询SYSID及组织ID，获取所对应的用户名
			List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
			String dbUser = "";// 用户名
			if (listConn.size() > 0) {
				Map<String, Object> connmap = listConn.get(0);
				dbUser = String.valueOf(connmap.get("DB_USER"));
			} else {
				throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
			}
			params.add(0, tableName);
			params.add(1, tableTitle);
			params.add(2, tableId);
			params.add(3, templetId);
			params.add(4, dbUser);
			commTableManagerDao.callProcedure("CBB_TABLEDEFINE_P.CREATE_TEMP_TABLE", params);
			SysLogUtil.log("库结构定义模块", "插入实体表记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
			throw new DaoException("创建动态表是出错！");
		}

	}

	/**
	 * cbbTabColumns该tid下的列最大排序值
	 *
	 * @param tid
	 * @return int
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public int selectMaxOrder(String tid) {
		int num = 0;
		String sql = "select max(t.col_order) from CBB_TAB_COLUMNS t where t.table_id = '" + tid + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		for (int i = 0; i < objList.size(); i++) {
			if (!"null".equals(String.valueOf(objList.get(i))) && !"".equals(String.valueOf(objList.get(i)))) {
				num = Integer.parseInt(String.valueOf(objList.get(i)));
			}
		}
		return num;
	}

	/**
	 * cbbTabColumns该tid下的列最大表格排序值
	 *
	 * @param tid
	 * @return int
	 * @throws
	 * @author 朱锋
	 */
	public int selectMaxTabOrder(String tid) {
		int num = 0;
		String sql = "select max(t.ATTRIBUTE_11) from CBB_TAB_COLUMNS t where t.table_id = '" + tid + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		for (int i = 0; i < objList.size(); i++) {
			if (null != objList.get(i) && !"null".equals(String.valueOf(objList.get(i))) && !"".equals(String.valueOf(objList.get(i)))) {
				num = Integer.parseInt(String.valueOf(objList.get(i)));
			}
		}
		return num;
	}

	/**
	 * CBB_TAB_NODE该TABLE_ID,NODE_ID,SYS_ID下的最大排序值
	 *
	 * @param nodeId
	 * @param sysId
	 * @return int
	 * @throws
	 * @author 朱锋
	 */
	public int selectMaxSort(String nodeId, String sysId) {
		int num = 0;
		String sql = "select max(t.TAB_ORDER) from CBB_TAB_NODE t where t.node_id = '" + nodeId + "' and t.sys_id = '" + sysId + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		for (int i = 0; i < objList.size(); i++) {
			if (!"null".equals(String.valueOf(objList.get(i)))) {
				num = Integer.parseInt(String.valueOf(objList.get(i)));
			}
		}
		return num;
	}

	/**
	 * 根据列信息ID获取该对象
	 *
	 * @param id
	 * @return CbbTabColumns
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public CbbTabColumns getCbbTabColumnsById(String id) throws Exception {
		CbbTabColumns h = (CbbTabColumns) hibernateDao.getSession().get(CbbTabColumns.class, id);
		return h;
	}

	/**
	 * 根据排序字段ID获取该对象
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 *             CbbTabColSort
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public CbbTabColSort getCbbTabColSortById(String id) {
		CbbTabColSort h = (CbbTabColSort) hibernateDao.getSession().get(CbbTabColSort.class, id);
		return h;
	}

	/**
	 * 根据分类检索ID获取该对象
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 *             CbbTabColSort
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public CbbTabColSearch getCbbTabColSearchById(String id) throws Exception{
		CbbTabColSearch h = (CbbTabColSearch) hibernateDao.getSession().get(CbbTabColSearch.class, id);
		return h;
	}

	/**
	 * 根据生成方式规则ID获取该对象
	 *
	 * @param id
	 * @return CbbTabFormSelect
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public CbbTabColCode getCbbTabColCodeById(String id) throws Exception {
		CbbTabColCode h = (CbbTabColCode) hibernateDao.getSession().get(CbbTabColCode.class, id);
		return h;
	}

	/**
	 * 根据生成方式规则ID获取该对象
	 */
	@Override
	public CbbTabFormSelect getCbbTabFormSelectById(String id) {
		CbbTabFormSelect h = (CbbTabFormSelect) hibernateDao.getSession().get(CbbTabFormSelect.class, id);
		return h;
	}

	/**
	 * 根据sysId和nodeId查询tableId
	 *
	 * @param sysId
	 * @param nodeId
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public String getTableIdBysnId(String sysId, String nodeId) {
		String tableId = "";
		String sql = "select t.table_id from CBB_TAB_NODE t where t.node_id ='" + nodeId + "' and t.sys_id = '" + sysId + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		if (objList != null && objList.size() > 0) {
			tableId = String.valueOf(objList.get(0));
		}
		return tableId;
	}

	/**
	 * 根据sysId和tableName查询tableId
	 *
	 * @param sysId
	 * @param tableName
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public String getTableIdBysysIdAndTableName(String sysId, String tableName, Map<String, Object> param) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = "";
		String orgId = "";
		if (param.containsKey("orgId")) {
			orgId = String.valueOf(param.get("orgId"));
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID\n");
		sbSql.append("  FROM CBB_TABLES T\n");
		sbSql.append(" WHERE T.TABLE_NAME = '" + tableName + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'");

		if (!"".equals(orgId) && !"null".equals(orgId)) {
			sbSql.append(" AND T.ORG_ID = '" + orgId + "'");
		}

		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			tableId = String.valueOf(objList.get(0));
		}
		return tableId;
	}

	/**
	 * 获取列信息
	 */
	@Override
	public Map<String, Object> getPageDetailList(Paging<CbbTabColumns> page, Map<String, Object> parameter, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tableId = String.valueOf(parameter.get("tableId"));
		String isTemplet = String.valueOf(parameter.get("isTemplet"));
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT T.*\n");
		sbSql.append("    FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("   WHERE (T.COL_IS_SYS = 'N' OR T.COL_IS_DISPLAY = 'Y')\n");
		sbSql.append("     AND T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME),\n");
		sbSql.append("T2 AS\n");
		sbSql.append(" (SELECT T.*\n");
		sbSql.append("    FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("   WHERE T.COL_IS_SYS = 'Y'\n");
		sbSql.append("     AND T.COL_IS_DISPLAY = 'N'\n");
		sbSql.append("     AND T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME),\n");
		sbSql.append("T3 AS\n");
		sbSql.append(" (SELECT T1.*\n");
		sbSql.append("    FROM T1\n");
		sbSql.append("  UNION ALL\n");
		sbSql.append("  SELECT T2.* FROM T2)\n");
		sbSql.append("SELECT T3.* FROM T3\n");
		if ("N".equals(isTemplet)) {
			sbSql.append(" WHERE T3.COL_IS_DISPLAY = 'Y'");
		}
		// SanXiaFiles Create By Tangkun Start
		String inputWord = String.valueOf(parameter.get("inputWord"));
		if (inputWord != null && !"".equals(inputWord) && inputWord != "null") {
			sbSql.append(" AND (T3.COL_NAME like '%" + inputWord + "%' OR T3.COL_LABEL like '%" + inputWord + "%')\n");
		}
		// SanXiaFiles Create By Tangkun End
		String sql = sbSql.toString();
		String sqlCount = "select count(1) from (" + sql + ")";
		List<Object> sqlCountList = hibernateDao.findBySQL(sqlCount);
		String count = String.valueOf(sqlCountList.get(0));
		int firstResult = page.getPageNo();
		int maxResults = page.getPageSize();
		if (firstResult <= 1) {
			sql = "select * from ( " + sql + " ) where rownum <= " + maxResults;
		} else {
			sql = "select * from ( select row_.*, rownum rownum_var from ( " + sql + " ) row_ where rownum <= " + (firstResult * maxResults) + ") where rownum_var > " + (firstResult - 1) * maxResults;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		List<CbbTabColumns> list = this.hibernateDao.getSession().createSQLQuery(sql).addEntity("T3", CbbTabColumns.class).list();
		map.put("count", count);
		map.put("list", list);
		return map;
	}

	/**
	 * 获取不可见字段的列信息
	 */
	@Override
	public Map<String, Object> getHiddenPageDetailList(Paging<CbbTabColumns> page, Map<String, Object> parameter, String sysId) throws Exception{
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tableId = String.valueOf(parameter.get("tableId"));
		// String isTemplet = String.valueOf(parameter.get("isTemplet"));
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT T.*\n");
		sbSql.append("    FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("   WHERE (T.COL_IS_SYS = 'N' OR T.COL_IS_DISPLAY = 'Y')\n");
		sbSql.append("     AND T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME),\n");
		sbSql.append("T2 AS\n");
		sbSql.append(" (SELECT T.*\n");
		sbSql.append("    FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("   WHERE T.COL_IS_SYS = 'Y'\n");
		sbSql.append("     AND T.COL_IS_DISPLAY = 'N'\n");
		sbSql.append("     AND T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME),\n");
		sbSql.append("T3 AS\n");
		sbSql.append(" (SELECT T1.*\n");
		sbSql.append("    FROM T1\n");
		sbSql.append("  UNION ALL\n");
		sbSql.append("  SELECT T2.* FROM T2)\n");
		sbSql.append("SELECT T3.* FROM T3\n");
		sbSql.append(" WHERE T3.COL_IS_DISPLAY = 'N'");
		String sql = sbSql.toString();
		String sqlCount = "select count(1) from (" + sql + ")";
		List<Object> sqlCountList = hibernateDao.findBySQL(sqlCount);
		String count = String.valueOf(sqlCountList.get(0));
		int firstResult = page.getPageNo();
		int maxResults = page.getPageSize();
		if (firstResult <= 1) {
			sql = "select * from ( " + sql + " ) where rownum <= " + maxResults;
		} else {
			sql = "select * from ( select row_.*, rownum rownum_var from ( " + sql + " ) row_ where rownum <= " + (firstResult * maxResults) + ") where rownum_var > " + (firstResult - 1) * maxResults;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		List<CbbTabColumns> list = this.hibernateDao.getSession().createSQLQuery(sql).addEntity("T3", CbbTabColumns.class).list();
		map.put("count", count);
		map.put("list", list);
		return map;
	}

	/**
	 * 获取列信息(只用于著录定义页面初始化加载数据)
	 *
	 * @throws Exception
	 */
	@Override
	public Map<String, Object> getPageDetailListForZL(Paging<CbbTabColumns> page, Map<String, Object> parameter, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tableId = String.valueOf(parameter.get("tableId"));
		String isTemplet = String.valueOf(parameter.get("isTemplet"));
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT T.*\n");
		sbSql.append("    FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("   WHERE (T.COL_IS_SYS = 'N' OR T.COL_IS_DISPLAY = 'Y')\n");
		sbSql.append("     AND T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME),\n");
		sbSql.append("T2 AS\n");
		sbSql.append(" (SELECT T.*\n");
		sbSql.append("    FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("   WHERE T.COL_IS_SYS = 'Y'\n");
		sbSql.append("     AND T.COL_IS_DISPLAY = 'N'\n");
		sbSql.append("     AND T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME),\n");
		sbSql.append("T3 AS\n");
		sbSql.append(" (SELECT T1.*\n");
		sbSql.append("    FROM T1\n");
		sbSql.append("  UNION ALL\n");
		sbSql.append("  SELECT T2.* FROM T2)\n");
		sbSql.append("SELECT T3.* FROM T3\n");
		if ("N".equals(isTemplet)) {
			sbSql.append(" WHERE T3.COL_IS_DISPLAY = 'Y'");
		}
		String sql = sbSql.toString();
		String sqlCount = "select count(1) from (" + sql + ")";
		List<Object> sqlCountList = hibernateDao.findBySQL(sqlCount);
		String count = String.valueOf(sqlCountList.get(0));
		int firstResult = page.getPageNo();
		int maxResults = page.getPageSize();
		if (firstResult <= 1) {
			sql = "select * from ( " + sql + " ) where rownum <= " + maxResults;
		} else {
			sql = "select * from ( select row_.*, rownum rownum_var from ( " + sql + " ) row_ where rownum <= " + (firstResult * maxResults) + ") where rownum_var > " + (firstResult - 1) * maxResults;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		List<CbbTabColumns> list = this.hibernateDao.getSession().createSQLQuery(sql).addEntity("T3", CbbTabColumns.class).list();
		// 根据dropdownType给colvalue赋值
		for (int i = 0; i < list.size(); i++) {
			CbbTabColumns cbbTabColumns = list.get(i);
			String dropdownType = cbbTabColumns.getColDropdownType();
			String geneMethodRule = cbbTabColumns.getColGeneMethodRule();// 生成方式规则值
			if ("1".equals(dropdownType)) { // 参选
				if ("2".equals(cbbTabColumns.getColGeneMethod())) { // 序列
					// 将序列值绑定在ColValueName上用于页面初始化显示
					cbbTabColumns.setColValueName(geneMethodRule);
				} else if ("4".equals(cbbTabColumns.getColGeneMethod())) { // 组合项
					// 根据字段ID获取组合项配置信息
					String groupConfig = this.getCofigGroupBySourceId(cbbTabColumns.getId());
					cbbTabColumns.setColValueName(groupConfig);
				} else if ("5".equals(cbbTabColumns.getColGeneMethod())) { // 统计生成
					// 根据字段ID获取组合项配置信息
					String groupConfig = this.getCofigTjscBySourceId(cbbTabColumns.getId());
					cbbTabColumns.setColValueName(groupConfig);
				} else {
					// 获取该字段通用代码集合
					List<Object[]> colCodeList = this.getLookupCodeByColumnId(cbbTabColumns.getId());
					boolean flag = false;// 参选字段生成方式是否为通用代码标识,默认不是
					for (int j = 0; j < colCodeList.size(); j++) {
						String lookupName = (String) colCodeList.get(j)[0];
						String lookupCode = (String) colCodeList.get(j)[1];
						// 根据生成方式规则值找通用代码lookupName
						if (lookupCode.equals(geneMethodRule)) {
							flag = true;
							cbbTabColumns.setColValueName(lookupName);
						}
					}
					if (!flag) { // 参选字段生成方式不是通用代码
						cbbTabColumns.setColValueName(geneMethodRule);
					}
				}
			} else if ("2".equals(dropdownType)) { // 只选
				// 获取该字段通用代码集合
				List<Object[]> colCodeList = this.getLookupCodeByColumnId(cbbTabColumns.getId());
				for (int j = 0; j < colCodeList.size(); j++) {
					String lookupName = (String) colCodeList.get(j)[0];
					String lookupCode = (String) colCodeList.get(j)[1];
					// 根据生成方式规则值找通用代码lookupName
					if (lookupCode.equals(geneMethodRule)) {
						cbbTabColumns.setColValueName(lookupName);
					}
				}
				/********** 2015/07/03更改 - 郭亮（统计生成） *************/
				if ("5".equals(cbbTabColumns.getColGeneMethod())) {
					// 根据字段ID获取组合项配置信息
					String groupConfig = this.getCofigTjscBySourceId(cbbTabColumns.getId());
					cbbTabColumns.setColValueName(groupConfig);
				}
			} else if ("3".equals(dropdownType)) { // 选择
				if (null != geneMethodRule) {
					/*
					 * if ("user".equals(cbbTabColumns.getColRuleName())) { // 选人 String userName = this.getUserNameById(geneMethodRule); cbbTabColumns.setColValueName(userName); }
					 * else if ("dept".equals(cbbTabColumns.getColRuleName())) { // 选部门 String deptName = this.getDeptNameById(geneMethodRule);
					 * cbbTabColumns.setColValueName(deptName); } else
					 */
					if ("custom".equals(cbbTabColumns.getColRuleName())) { // 自定义选择页
						String customPath = cbbTabColumns.getCustomPath();
						String customName = this.getCustomValue(geneMethodRule, customPath);
						cbbTabColumns.setColValueName(customName);
					} else {
						cbbTabColumns.setColValueName(geneMethodRule);
					}
				}
				/********** 2015/07/03更改 - 郭亮（统计生成） *************/
				if ("5".equals(cbbTabColumns.getColGeneMethod())) {
					// 根据字段ID获取组合项配置信息
					String groupConfig = this.getCofigTjscBySourceId(cbbTabColumns.getId());
					cbbTabColumns.setColValueName(groupConfig);
				}
			} else { // 普通字段
				if ("4".equals(cbbTabColumns.getColGeneMethod())) { // 组合项
					// 根据字段ID获取组合项配置信息
					//edit by zhangjq 2019-8-3
					//String groupConfig = this.getCofigGroupBySourceId(cbbTabColumns.getId());
					//cbbTabColumns.setColValueName(groupConfig);
					cbbTabColumns.setColValueName(cbbTabColumns.getColGeneMethodRuleText());
					//end edit

				} else if ("5".equals(cbbTabColumns.getColGeneMethod())) { // 统计生成
					// 根据字段ID获取组合项配置信息
					String groupConfig = this.getCofigTjscBySourceId(cbbTabColumns.getId());
					cbbTabColumns.setColValueName(groupConfig);
				} else {
					cbbTabColumns.setColValueName(geneMethodRule);
				}
			}
			// 顺带
			if ("3".equals(cbbTabColumns.getColGeneMethod())) {
				if (null != geneMethodRule && !"".equals(geneMethodRule)) {
					String[] params = geneMethodRule.split(",");
					String paramTableId = params[0];
					String paramColumnsId = params[1];
					CbbTables ct = this.getCbbTablesById(paramTableId);
					CbbTabColumns ctc = this.getCbbTabColumnsById(paramColumnsId);
					cbbTabColumns.setColValueName(ct.getTableTitle() + "." + ctc.getColLabel());
				}
			}
		}
		map.put("count", count);
		map.put("list", list);
		return map;
	}

	/**
	 * 删除基本字段信息
	 *
	 * @param id
	 * @param sysId
	 * @throws Exception
	 */
	@Override
	public void deleteCommCbbTabColumnsById(CbbTabColumns[] cbbTabColumnsArray, String sysId, String nodeId, String nodeName, String tableName, String isTrueTable, String orgId, Map<String, Object> param) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String nameParam = ""; // 级联删除字段对应设置参数，字段名，多个用英文逗号分割
		String tableIdParam = ""; // 级联删除字段对应设置参数，表ID
		// String orgCode = (String) param.get("orgCode");
		for (int i = 0; i < cbbTabColumnsArray.length; i++) {
			try {
				CbbTabColumns cbbTabColumns = cbbTabColumnsArray[i];
				if (null != cbbTabColumns) {
					// 构造删除字段对应设置配置信息参数
					tableIdParam = cbbTabColumns.getTableId();
					nameParam = nameParam + "," + cbbTabColumns.getColName();
					// 删除CBB_TAB_COL_CODE配置信息
					String deleteCodeSql = "DELETE FROM CBB_TAB_COL_CODE T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteCodeSql);
					SysLogUtil.log("库结构定义模块", "删除代码维护记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除CBB_TAB_COL_INDEX配置信息
					String deleteIndexSql = "DELETE FROM CBB_TAB_COL_INDEX T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteIndexSql);
					SysLogUtil.log("库结构定义模块", "删除唯一索引记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除CBB_TAB_COL_SEARCH配置信息
					String deleteSearchSql = "DELETE FROM CBB_TAB_COL_SEARCH T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteSearchSql);
					SysLogUtil.log("库结构定义模块", "删除分类检索记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除CBB_TAB_COL_SORT配置信息
					String deleteSortSql = "DELETE FROM CBB_TAB_COL_SORT T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteSortSql);
					SysLogUtil.log("库结构定义模块", "删除排序设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除CBB_TAB_COL_SYS_CODE配置信息
					String deleteSysCodeSql = "DELETE FROM CBB_TAB_COL_SYS_CODE T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteSysCodeSql);
					SysLogUtil.log("库结构定义模块", "删除代码维护-平台通用记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除CBB_TAB_FORM_CONFIG配置信息
					String deleteFormConfigSql = "DELETE FROM CBB_TAB_FORM_CONFIG T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteFormConfigSql);
					SysLogUtil.log("库结构定义模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除CBB_TAB_NODE_RECORD配置信息
					String deleteNodeRecordSql = "DELETE FROM CBB_TAB_NODE_RECORD T WHERE T.COLUMN_ID = '" + cbbTabColumns.getId() + "'";
					jdbcTemplate.update(deleteNodeRecordSql);
					SysLogUtil.log("库结构定义模块", "删除节点著录定义表记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					SysLogUtil.log("库结构定义模块", "删除字段对应设置明细信息表记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					// 删除基本字段信息
					hibernateDao.delete(cbbTabColumns);
					SysLogUtil.log(cbbTabColumns, null, OpType.delete, OpResult.success);
					// 查询SYSID及组织ID，获取所对应的用户名
					List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
					String dbUser = "";// 用户名
					if (listConn.size() > 0) {
						Map<String, Object> connmap = listConn.get(0);
						dbUser = String.valueOf(connmap.get("DB_USER"));
					} else {
						throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
					}
					// 虚拟表不能删除表字段
					if (!"N".equals(isTrueTable)) {
						// 删除基本字段所对应的实体表字段
						String dropcol = "ALTER TABLE " + dbUser + "." + tableName + " DROP COLUMN " + cbbTabColumns.getColName();
						this.jdbcAvicit.getJdbcTemplate().execute(dropcol);
						this.jdbcAvicit.getJdbcTemplate().execute("commit");
						SysLogUtil.log("库结构定义模块", "删除实体表列记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
					}

					//删除相关联的组合项配置
					deleteCombinationByCbbTabColumn(cbbTabColumns,tableName);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		// 删除LANTOP_FIELD_RELATE_SET_ITEM配置信息
		if (!"".equals(nameParam)) {
			nameParam = nameParam.substring(1);
		}
		Map<String, String> relateSetParam = new HashMap<String, String>();
		relateSetParam.put("tableId", tableIdParam);
		relateSetParam.put("orgId", orgId);
		relateSetParam.put("colName", nameParam);
		// 调用rest服务，删除字段对应设置配置信息并更新档案大视图
		FieldMapSetRestClient fieldMapSetRestClient = new FieldMapSetRestClient("/api/im/lantop/basic/fieldmapset");
		RestClient.doPost(fieldMapSetRestClient.getRestUrl("/updateConfig/v1"), relateSetParam, new GenericType<ResponseMsg<Integer>>() {
		});
		// if (responseMsg.getRetCode().equals(ResponseStatus.HTTP_OK)) {
		// } else {
		// throw new RuntimeException(responseMsg.getErrorDesc());
		// }
	}

	/**
	 * 删除代码维护信息
	 *
	 * @param id
	 * @param sysId
	 * @throws Exception
	 */
	@Override
	public void deleteCbbTabColCodeById(CbbTabColCode cbbTabColCode) throws Exception {
		try {
			// 删除基本字段信息
			hibernateDao.delete(cbbTabColCode);
			SysLogUtil.log(cbbTabColCode, null, OpType.delete, OpResult.success);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除生成方式规则信息
	 *
	 * @param id
	 * @param sysId
	 * @throws Exception
	 */
	@Override
	public void deleteCbbTabFormSelectById(CbbTabFormSelect cbbTabFormSelect) throws Exception {
		try {
			// 删除基本字段信息
			hibernateDao.delete(cbbTabFormSelect);
			SysLogUtil.log(cbbTabFormSelect, null, OpType.delete, OpResult.success);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除列信息
	 *
	 * @param id
	 * @param sysId
	 * @throws Exception
	 */
	public void deleteCbbTabColumnsById(CbbTabColumns cbbTabColumns) throws Exception {
		try {
			// 删除基本字段信息
			hibernateDao.delete(cbbTabColumns);
			SysLogUtil.log(cbbTabColumns, null, OpType.delete, OpResult.success);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 递归获取Tree当前节点下数据
	 *
	 * @param id
	 * @param orgId
	 * @param sysId
	 * @return 节点集合
	 */
	@Override
	public List<TreeNode> getTableTreeNodes(String id, String sysId, String orgId) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 递归一层减一层
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		// 查询业务数据
		List<Map<String, Object>> childTreeList = this.findCommTempletInfoNodesByParentId(id, sysId, orgId);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : childTreeList) {
			String rid = (String) row.get("id");
			String rname = "";
			rname = (String) row.get("TEMP_NAME");
			String tempType = (String) row.get("TEMP_TYPE");
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			// 根据节点类型,设置节点图标
			if (null != tempType && "R".equals(tempType)) { // R根节点
				node.setIconCls("icon-im-newnrootnode");
			} else if (null != tempType && "O".equals(tempType)) { // 0 组织标识
				node.setIconCls("icon-im-newnorg");
			} else if (null != tempType && "F".equals(tempType)) { // F 模板夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != tempType && "C".equals(tempType)) { // C 模板
				node.setIconCls("icon-im-newntable");
			} else if (null != tempType && "S".equals(tempType)) { // S 系统标识
				node.setIconCls("icon-im-newnmodulefile");
			}
			node.setAttributes(row);
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = getTableTreeNodes(rid, sysId, orgId);
				node.getChildren().addAll(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodes.add(node);
		}
		return nodes;
	}

	/**
	 * 获取子节点
	 *
	 * @param parentId
	 * @param orgId
	 * @return
	 */
	public List<Map<String, Object>> findCommTempletInfoNodesByParentId(String parentId, String sysId, String orgId) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		Assert.notNull(parentId, "参数不能为空！");
		String sql = "SELECT T.*,\n" + "       (SELECT COUNT(*)\n" + "          FROM CBB_TEMPLET_V F\n" + "         WHERE F.PARENT_ID = '" + parentId + "'" + " \n" + "        ) CHILD_COUNT\n" + "  FROM CBB_TEMPLET_V T\n" + " WHERE T.PARENT_ID = '" + parentId
				+ "'   AND (T.SYS_ID='-1' OR T.SYS_ID = '" + sysId + "' OR T.SYS_ID = 'O') AND (T.ORG_ID = '" + orgId + "' OR T.ORG_ID = 'ORG_ROOT' OR T.ORG_ID = 'TEMPLATE_ROOT')\n" + "CONNECT BY PRIOR T.ID = T.PARENT_ID\n" + " START WITH T.PARENT_ID = '" + parentId + "'";
		return jdbcTemplate.queryForList(sql);
	}

	/**
	 * 复制参考模板字段信息
	 */
	@Override
	public void copyCommTempletField(String ids, String sysId, String tableName, String orgId, String deptId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		// 判断该表是否为真实表
		boolean isTrueTable = true;// 默认为真实表
		String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
		CbbTables cbbTables = getCbbTablesById(tableId);
		if ("N".equals(cbbTables.getTableIsTrueTable())) {
			isTrueTable = false;
		}
		String[] fieldIds = ids.split(",");// 参考模板字段数组
		for (String fid : fieldIds) {
			boolean flag = checkField(fid, sysId, tableId);
			if (!flag) {
				// 1.复制基本信息
				CbbTempletField cbbTempletField = getCommTempletFieldById(fid);// 参考模板字段对象
				CbbTabColumns cbbTabColumns = new CbbTabColumns();
				String cid = ComUtil.getId();
				cbbTabColumns.setId(cid);
				cbbTabColumns.setTableId(tableId);
				cbbTabColumns.setColName(cbbTempletField.getColName());
				cbbTabColumns.setColLabel(cbbTempletField.getColLabel());
				cbbTabColumns.setColType(cbbTempletField.getColType());
				cbbTabColumns.setColLength(cbbTempletField.getColLength());
				cbbTabColumns.setColDecimal(cbbTempletField.getColDecimal());
				cbbTabColumns.setColIsSys("N");
				// 取cbbTabColumns该tid下的最大排序值
				int num = selectMaxOrder(tableId) + 1;
				BigDecimal colOrder = new BigDecimal(num);
				cbbTabColumns.setColOrder(colOrder);
				// 取cbbTabColumns该tid下的最大表格排序值
				int numtab = selectMaxTabOrder(tableId) + 1;
				BigDecimal colTabOrder = new BigDecimal(numtab);
				cbbTabColumns.setAttribute11(colTabOrder);
				cbbTabColumns.setColIsMust(cbbTempletField.getColIsMust());
				cbbTabColumns.setColIsVisible(cbbTempletField.getColIsVisible());
				cbbTabColumns.setColIsSearch(cbbTempletField.getColIsSearch());
				cbbTabColumns.setColIsEdit(cbbTempletField.getColIsEdit());
				cbbTabColumns.setColIsTabVisible(cbbTempletField.getColIsTabVisible());
				cbbTabColumns.setColIsDetail(cbbTempletField.getColIsDetail());
				cbbTabColumns.setColDropdownType(cbbTempletField.getColDropdownType());
				cbbTabColumns.setColGeneMethod("0");
				cbbTabColumns.setColRuleName(cbbTempletField.getColRuleName());
				cbbTabColumns.setColRuleTitle(cbbTempletField.getColRuleTitle());
				cbbTabColumns.setCustomPath(cbbTempletField.getCustomPath());
				cbbTabColumns.setRemark(cbbTempletField.getRemark());
				cbbTabColumns.setOrgId(orgId);
				cbbTabColumns.setDeptId(deptId);
				cbbTabColumns.setSysId(sysId);
				cbbTabColumns.setColIsDisplay(cbbTempletField.getColIsDisplay());
				cbbTabColumns.setColShowFormat("0");
				cbbTabColumns.setColIsDisplay(cbbTempletField.getColIsDisplay());
				cbbTabColumns.setColGeneMethodRule("");
				PojoUtil.setSysProperties(cbbTabColumns, OpType.insert);
				hibernateDao.save(cbbTabColumns);
				SysLogUtil.log(cbbTabColumns, null, OpType.insert, OpResult.success);
				if (isTrueTable) {
					// 查询SYSID及组织ID，获取所对应的用户名
					List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
					String dbUser = "";// 用户名
					if (listConn.size() > 0) {
						Map<String, Object> connmap = listConn.get(0);
						dbUser = String.valueOf(connmap.get("DB_USER"));
					} else {
						throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
					}
					try {
						// 给实体表新增字段
						String colType = "";
						if (cbbTabColumns.getColType().equals("string")) {
							colType = "VARCHAR2(" + (null == cbbTabColumns.getColLength() ? "128" : cbbTabColumns.getColLength()) + ")";
						} else if (cbbTabColumns.getColType().equals("integer")) {
							colType = "NUMBER";
							if (null != cbbTabColumns.getColLength()) {
								colType = colType + "(" + cbbTabColumns.getColLength() + ")";
							}
						} else if (cbbTabColumns.getColType().equals("date")) {
							colType = "DATE";
						} else if (cbbTabColumns.getColType().equals("float")) {
							colType = "NUMBER";
							if (cbbTabColumns.getColLength() != null) {
								colType = colType + "(" + cbbTabColumns.getColLength() + ",";
							} else {
								colType = colType + "(16,";
							}
							colType = colType + cbbTabColumns.getColDecimal() + ")";
						} else if (cbbTabColumns.getColType().equals("blob")) {
							colType = "BLOB";
						} else if (cbbTabColumns.getColType().equals("clob")) {
							colType = "CLOB";
						}
						String addCol = "ALTER TABLE " + dbUser + "." + tableName + " ADD " + cbbTabColumns.getColName() + " " + colType;
						this.jdbcAvicit.getJdbcTemplate().execute(addCol);
						this.jdbcAvicit.getJdbcTemplate().execute("commit");
						SysLogUtil.log("库结构定义模块", "新增实体表列记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
						// 给此字段增加注释
						addCol = "COMMENT ON COLUMN " + tableName + "." + cbbTabColumns.getColName() + "\n" + "  is '" + cbbTabColumns.getColLabel() + "'";
						this.jdbcAvicit.getJdbcTemplate().execute(addCol);
						this.jdbcAvicit.getJdbcTemplate().execute("commit");
						SysLogUtil.log("库结构定义模块", "新增实体表列注释记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
					} catch (Exception e) {
						e.printStackTrace();
						SysLogUtil.log("库结构定义模块", "新增实体表列记录", OpType.insert, OpResult.failure, LogBaseFactory.getLogBase());
					}
					/****************** 复制对应字段多语言信息 ******************/

					CbbTabColumnsTlDTO cbbTabColumnsTlDTO = new CbbTabColumnsTlDTO();
					List<Map<String, Object>> list = cbbTabColumnsTlService.findSysLanguageByParentId2(cbbTempletField.getId());
					for (int i = 0; i < list.size(); i++) {
						String sysLanguageCode = list.get(i).get("SYS_LANGUAGE_CODE").toString();// 语言代码
						String columnsShowName = list.get(i).get("COLUMNS_SHOW_NAME").toString();// 列显示名称
						String description = list.get(i).get("DESCRIPTION").toString();// 描述
						cbbTabColumnsTlDTO.setSysLanguageCode(sysLanguageCode);
						cbbTabColumnsTlDTO.setCbbTabColumnsId(cid);
						cbbTabColumnsTlDTO.setColumnsShowName(columnsShowName);
						cbbTabColumnsTlDTO.setDescription(description);
						cbbTabColumnsTlService.insertCbbTabColumnsTl(cbbTabColumnsTlDTO);

					}

				}
				// 2复制该字段的通用代码信息
				// 2.1复制通用代码信息（CBB_TAB_COL_SYS_CODE表）
				String codeSql = "SELECT T.SYS_LOOKUP_ID,T.REMARK ,T.ID FROM CBB_TEMPLET_SYS_CODE T WHERE T.TEMPLET_ID = '" + cbbTempletField.getTempletId() + "' AND T.FIELD_ID = '" + cbbTempletField.getId() + "'";
				List<Object[]> codeList = this.hibernateDao.findBySQL(codeSql);
				if (codeList != null && codeList.size() > 0) {
					CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
					cbbTabColSysCode.setSysLookupId(codeList.get(0)[0].toString());
					cbbTabColSysCode.setRemark(codeList.get(0)[1] == null ? "" : codeList.get(0)[1].toString());
					String id = ComUtil.getId();
					cbbTabColSysCode.setId(id);
					cbbTabColSysCode.setTableId(cbbTabColumns.getTableId());
					cbbTabColSysCode.setColumnId(cbbTabColumns.getId());
					cbbTabColSysCode.setOrgId(orgId);
					cbbTabColSysCode.setDeptId(deptId);
					cbbTabColSysCode.setSysId(sysId);
					PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
					hibernateDao.save(cbbTabColSysCode);
					SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
				}
				// 2.2复制通用代码信息（CBB_TAB_COL_CODE表）
				String codeSql2 = "SELECT T.CODE_ORDER,T.CODE_IS_VALID,T.LOOKUP_NAME,T.LOOKUP_CODE,T.REMARK ,T.ID FROM CBB_TEMPLET_CODE T WHERE T.TEMPLET_ID = '" + cbbTempletField.getTempletId() + "' AND T.FIELD_ID = '" + cbbTempletField.getId() + "'";
				List<Object[]> codeList2 = this.hibernateDao.findBySQL(codeSql2);
				for (int i = 0; i < codeList2.size(); i++) {
					CbbTabColCode cbbTabColCode = new CbbTabColCode();
					cbbTabColCode.setCodeOrder(new BigDecimal(codeList2.get(i)[0].toString()));
					cbbTabColCode.setCodeIsValid(codeList2.get(i)[1].toString());
					cbbTabColCode.setLookupName(codeList2.get(i)[2].toString());
					cbbTabColCode.setLookupCode(codeList2.get(i)[3].toString());
					cbbTabColCode.setRemark(codeList2.get(i)[4] == null ? "" : codeList2.get(i)[4].toString());
					cbbTabColCode.setTableId(cbbTabColumns.getTableId());
					cbbTabColCode.setColumnId(cbbTabColumns.getId());
					cbbTabColCode.setDeptId(deptId);
					cbbTabColCode.setOrgId(orgId);
					cbbTabColCode.setSysId(sysId);
					this.insertTabColCode(cbbTabColCode);
					/**************** 复制通用代码多语言信息（针对CBB_TAB_COL_CODE表的多语言信息） *************************/
					String codeSqlLanguange = "SELECT T.SYS_LANGUAGE_CODE,T.COLUMNS_SHOW_NAME,T.DESCRIPTION,T.ID FROM CBB_TEMPLET_CODE_TL T WHERE  T.CBB_TEMPLET_CODE_ID = '" + codeList2.get(i)[5].toString() + "'";
					List<Object[]> LanguangeCodeList2 = this.hibernateDao.findBySQL(codeSqlLanguange);
					for (int i2 = 0; i2 < LanguangeCodeList2.size(); i2++) {
						CbbTabColCodeTlDTO cbbTabColCodeTlDTO = new CbbTabColCodeTlDTO();
						cbbTabColCodeTlDTO.setCbbTabColCodeId(cbbTabColCode.getId());
						cbbTabColCodeTlDTO.setSysLanguageCode(LanguangeCodeList2.get(i2)[0].toString());
						cbbTabColCodeTlDTO.setColumnsShowName(LanguangeCodeList2.get(i2)[1].toString());
						cbbTabColCodeTlDTO.setDescription(LanguangeCodeList2.get(i2)[2].toString());
						cbbTabColCodeTlService.insertCbbTabColCodeTl(cbbTabColCodeTlDTO);

					}
				}

				// 3同步节点著录定义配置信息
				// Map<String, Object> tabNodeRecordParam = new HashMap<String,
				// Object>();
				// tabNodeRecordParam.put("sysId", sysId);
				// tabNodeRecordParam.put("orgId", orgId);
				// tabNodeRecordParam.put("deptId", deptId);
				// tabNodeRecordParam.put("tableId", tableId);
				// tabNodeRecordParam.put("obj", cbbTabColumns);
				// this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
				// 4、给表单配置信息表添加数据
				List<String> formIdList = getFormIdByTableIdByFormConfig(sysId, tableId);// formId
				String formId = "";
				if (formIdList.size() > 0) {
					formId = formIdList.get(0);
				}
				if (!"".equals(formId)) {
					// 根据formId和columnId判断该字段是否已经存在配置信息
					boolean hasConfig = billDefineManagerService.getformConfigByFormIdAndColId(formId, cid);
					if (!hasConfig) {
						String formConfigId = ComUtil.getId();
						CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
						cbbTabFormConfig.setId(formConfigId);
						cbbTabFormConfig.setFormId(formId);
						cbbTabFormConfig.setColumnId(cid);
						BigDecimal formVertical = new BigDecimal(1);
						cbbTabFormConfig.setFormVertical(formVertical);
						BigDecimal formHorizontal = new BigDecimal(1);
						cbbTabFormConfig.setFormHorizontal(formHorizontal);
						cbbTabFormConfig.setOrgId(orgId);
						cbbTabFormConfig.setDeptId(deptId);
						cbbTabFormConfig.setSysId(sysId);
						cbbTabFormConfig.setAttribute11(cbbTabColumns.getColOrder());
						PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
						hibernateDao.save(cbbTabFormConfig);
						SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
					}
				}
			}
		}
	}

	/**
	 * 根据参考模板字段信息ID查询根据参考模板字段数据
	 */
	public CbbTempletField getCommTempletFieldById(String id) {
		CbbTempletField h = (CbbTempletField) hibernateDao.getSession().get(CbbTempletField.class, id);
		return h;
	}

	/***
	 * 复制库结构字段
	 */
	@Override
	public void copyCbbTabColumns(String ids, String sysId, String tableName, String orgId, String deptId, Map<String, Object> params) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		// 判断该表是否为真实表
		boolean isTrueTable = true;// 默认为真实表
		String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
		CbbTables cbbTables = getCbbTablesById(tableId);
		if ("N".equals(cbbTables.getTableIsTrueTable())) {
			isTrueTable = false;
		}
		// id数组
		String[] fieldIds = ids.split(",");
		for (String fid : fieldIds) {
			// 验证字段重复
			// boolean flag = checkCbbColumnsField(fid, sysId, tableId);
			// if (!flag) {
			// 1.复制基本字段信息
			// 给基本字段表添加数据
			CbbTabColumns cbbTabColumnsCopyed = getCbbTabColumnsById(fid);// 库结构字段对象
			CbbTabColumns cbbTabColumns = new CbbTabColumns();
			String cid = ComUtil.getId();
			cbbTabColumns.setId(cid);
			cbbTabColumns.setTableId(tableId);
			cbbTabColumns.setColName(cbbTabColumnsCopyed.getColName());
			cbbTabColumns.setColLabel(cbbTabColumnsCopyed.getColLabel());
			cbbTabColumns.setColType(cbbTabColumnsCopyed.getColType());
			cbbTabColumns.setColLength(cbbTabColumnsCopyed.getColLength());
			cbbTabColumns.setColDecimal(cbbTabColumnsCopyed.getColDecimal());
			cbbTabColumns.setColIsSys("N");
			// 取cbbTabColumns该tid下的最大排序值
			int num = selectMaxOrder(tableId) + 1;
			BigDecimal colOrder = new BigDecimal(num);
			cbbTabColumns.setColOrder(colOrder);
			// 取cbbTabColumns该tid下的最大表格排序值
			int numtab = selectMaxTabOrder(tableId) + 1;
			BigDecimal colTabOrder = new BigDecimal(numtab);
			cbbTabColumns.setAttribute11(colTabOrder);
			cbbTabColumns.setColIsMust(cbbTabColumnsCopyed.getColIsMust());
			cbbTabColumns.setColIsVisible(cbbTabColumnsCopyed.getColIsVisible());
			cbbTabColumns.setColIsSearch(cbbTabColumnsCopyed.getColIsSearch());
			cbbTabColumns.setColIsEdit(cbbTabColumnsCopyed.getColIsEdit());
			cbbTabColumns.setColIsTabVisible(cbbTabColumnsCopyed.getColIsTabVisible());
			cbbTabColumns.setColIsDetail(cbbTabColumnsCopyed.getColIsDetail());
			cbbTabColumns.setColDropdownType(cbbTabColumnsCopyed.getColDropdownType());
			cbbTabColumns.setColGeneMethod("0");
			cbbTabColumns.setColRuleName(cbbTabColumnsCopyed.getColRuleName());
			cbbTabColumns.setColRuleTitle(cbbTabColumnsCopyed.getColRuleTitle());
			cbbTabColumns.setCustomPath(cbbTabColumnsCopyed.getCustomPath());
			cbbTabColumns.setRemark(cbbTabColumnsCopyed.getRemark());
			cbbTabColumns.setOrgId(orgId);
			cbbTabColumns.setDeptId(deptId);
			cbbTabColumns.setSysId(sysId);
			cbbTabColumns.setColIsDisplay(cbbTabColumnsCopyed.getColIsDisplay());
			// 设置配置信息的值
			cbbTabColumns.setColGeneMethodRule("");
			cbbTabColumns.setColShowFormat("0");
			PojoUtil.setSysProperties(cbbTabColumns, OpType.insert);
			hibernateDao.save(cbbTabColumns);
			SysLogUtil.log(cbbTabColumns, null, OpType.insert, OpResult.success);
			if (isTrueTable) { // 如果为真实表，那么进行实体表操作
				// 查询SYSID及组织ID，获取所对应的用户名
				List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
				String dbUser = "";// 用户名
				if (listConn.size() > 0) {
					Map<String, Object> connmap = listConn.get(0);
					dbUser = String.valueOf(connmap.get("DB_USER"));
				} else {
					throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
				}
				try {
					// 给实体表新增字段
					String colType = "";
					if (cbbTabColumns.getColType().equals("string")) {
						colType = "VARCHAR2(" + (null == cbbTabColumns.getColLength() ? "128" : cbbTabColumns.getColLength()) + ")";
					} else if (cbbTabColumns.getColType().equals("integer")) {
						colType = "NUMBER";
						if (null != cbbTabColumns.getColLength()) {
							colType = colType + "(" + cbbTabColumns.getColLength() + ")";
						}
					} else if (cbbTabColumns.getColType().equals("date")) {
						colType = "DATE";
					} else if (cbbTabColumns.getColType().equals("float")) {
						colType = "NUMBER";
						if (cbbTabColumns.getColLength() != null) {
							colType = colType + "(" + cbbTabColumns.getColLength() + ",";
						} else {
							colType = colType + "(16,";
						}
						colType = colType + cbbTabColumns.getColDecimal() + ")";
					} else if (cbbTabColumns.getColType().equals("blob")) {
						colType = "BLOB";
					} else if (cbbTabColumns.getColType().equals("clob")) {
						colType = "CLOB";
					}
					String addCol = "ALTER TABLE " + dbUser + "." + tableName + " ADD " + cbbTabColumns.getColName() + " " + colType;
					this.jdbcAvicit.getJdbcTemplate().execute(addCol);
					this.jdbcAvicit.getJdbcTemplate().execute("commit");
					SysLogUtil.log("库结构定义模块", "新增实体表列记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
					// 给此字段增加注释
					addCol = "COMMENT ON COLUMN " + tableName + "." + cbbTabColumns.getColName() + "\n" + "  is '" + cbbTabColumns.getColLabel() + "'";
					this.jdbcAvicit.getJdbcTemplate().execute(addCol);
					this.jdbcAvicit.getJdbcTemplate().execute("commit");
					SysLogUtil.log("库结构定义模块", "新增实体表列注释记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());

					/****************** 复制 复制 库结构树对应字段多语言信息 ******************/

					CbbTabColumnsTlDTO cbbTabColumnsTlDTO = new CbbTabColumnsTlDTO();
					List<Map<String, Object>> list = cbbTabColumnsTlService.findSysLanguageByParentId(fid);
					for (int i = 0; i < list.size(); i++) {
						String sysLanguageCode = list.get(i).get("SYS_LANGUAGE_CODE").toString();// 语言代码
						String columnsShowName = list.get(i).get("COLUMNS_SHOW_NAME").toString();// 列显示名称
						String description = list.get(i).get("DESCRIPTION").toString();// 描述
						cbbTabColumnsTlDTO.setSysLanguageCode(sysLanguageCode);
						cbbTabColumnsTlDTO.setCbbTabColumnsId(cid);
						cbbTabColumnsTlDTO.setColumnsShowName(columnsShowName);
						cbbTabColumnsTlDTO.setDescription(description);
						cbbTabColumnsTlService.insertCbbTabColumnsTl(cbbTabColumnsTlDTO);

					}

				} catch (Exception e) {
					e.printStackTrace();
					SysLogUtil.log("库结构定义模块", "新增实体表列记录", OpType.insert, OpResult.failure, LogBaseFactory.getLogBase());
				}
			}
			// 2.复制代码维护信息
			// 2.1复制通用代码信息（CBB_TAB_COL_SYS_CODE表）
			String codeSql = "SELECT T.SYS_LOOKUP_ID,T.REMARK FROM CBB_TAB_COL_SYS_CODE T WHERE T.TABLE_ID = '" + cbbTabColumnsCopyed.getTableId() + "' AND T.COLUMN_ID = '" + cbbTabColumnsCopyed.getId() + "'";
			List<Object[]> codeList = this.hibernateDao.findBySQL(codeSql);
			if (codeList != null && codeList.size() > 0) {
				CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
				cbbTabColSysCode.setSysLookupId(codeList.get(0)[0].toString());
				cbbTabColSysCode.setRemark(codeList.get(0)[1] == null ? "" : codeList.get(0)[1].toString());
				String id = ComUtil.getId();
				cbbTabColSysCode.setId(id);
				cbbTabColSysCode.setTableId(cbbTabColumns.getTableId());
				cbbTabColSysCode.setColumnId(cbbTabColumns.getId());
				cbbTabColSysCode.setOrgId(orgId);
				cbbTabColSysCode.setDeptId(deptId);
				cbbTabColSysCode.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
				hibernateDao.save(cbbTabColSysCode);
				SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
			}
			// 2.2复制通用代码信息（CBB_TAB_COL_CODE表）
			String codeSql2 = "SELECT T.CODE_ORDER,T.CODE_IS_VALID,T.LOOKUP_NAME,T.LOOKUP_CODE,T.REMARK ,T.ID FROM CBB_TAB_COL_CODE T WHERE T.TABLE_ID = '" + cbbTabColumnsCopyed.getTableId() + "' AND T.COLUMN_ID = '" + cbbTabColumnsCopyed.getId() + "'";
			List<Object[]> codeList2 = this.hibernateDao.findBySQL(codeSql2);
			for (int i = 0; i < codeList2.size(); i++) {
				CbbTabColCode cbbTabColCode = new CbbTabColCode();
				cbbTabColCode.setCodeOrder(new BigDecimal(codeList2.get(i)[0].toString()));
				cbbTabColCode.setCodeIsValid(codeList2.get(i)[1].toString());
				cbbTabColCode.setLookupName(codeList2.get(i)[2].toString());
				cbbTabColCode.setLookupCode(codeList2.get(i)[3].toString());
				cbbTabColCode.setRemark(codeList2.get(i)[4] == null ? "" : codeList2.get(i)[4].toString());
				cbbTabColCode.setTableId(cbbTabColumns.getTableId());
				cbbTabColCode.setColumnId(cbbTabColumns.getId());
				cbbTabColCode.setDeptId(deptId);
				cbbTabColCode.setOrgId(orgId);
				cbbTabColCode.setSysId(sysId);
				this.insertTabColCode(cbbTabColCode);

				/**************** 复制通用代码多语言信息（针对CBB_TAB_COL_CODE表的多语言信息） *************************/
				String codeSqlLanguange = "SELECT T.SYS_LANGUAGE_CODE,T.COLUMNS_SHOW_NAME,T.DESCRIPTION,T.ID FROM CBB_TAB_COL_CODE_TL T WHERE  T.CBB_TAB_COL_CODE_ID = '" + codeList2.get(i)[5].toString() + "'";
				List<Object[]> LanguangeCodeList2 = this.hibernateDao.findBySQL(codeSqlLanguange);
				for (int i2 = 0; i2 < LanguangeCodeList2.size(); i2++) {
					CbbTabColCodeTlDTO cbbTabColCodeTlDTO = new CbbTabColCodeTlDTO();
					cbbTabColCodeTlDTO.setCbbTabColCodeId(cbbTabColCode.getId());
					cbbTabColCodeTlDTO.setSysLanguageCode(LanguangeCodeList2.get(i2)[0].toString());
					cbbTabColCodeTlDTO.setColumnsShowName(LanguangeCodeList2.get(i2)[1].toString());
					cbbTabColCodeTlDTO.setDescription(LanguangeCodeList2.get(i2)[2].toString());
					cbbTabColCodeTlService.insertCbbTabColCodeTl(cbbTabColCodeTlDTO);

				}

			}
			// 3.复制索引信息(INDEX_NAME,INDEX_TYPE，REMARK)
			String indexSql = "SELECT T.INDEX_NAME,T.INDEX_TYPE,T.REMARK FROM CBB_TAB_COL_INDEX T WHERE T.TABLE_ID = '" + cbbTabColumnsCopyed.getTableId() + "' AND T.COLUMN_ID = '" + cbbTabColumnsCopyed.getId() + "'";
			List<Object[]> indexList = this.hibernateDao.findBySQL(indexSql);
			for (int i = 0; i < indexList.size(); i++) {
				String indexName = String.valueOf(indexList.get(i)[0]);
				String indexType = String.valueOf(indexList.get(i)[1]);
				CbbTabColIndex cbbTabColIndex = new CbbTabColIndex();
				cbbTabColIndex.setIndexName(indexName);
				cbbTabColIndex.setIndexType(indexType);
				cbbTabColIndex.setRemark(indexList.get(i)[2] == null ? "" : indexList.get(i)[2].toString());
				String id = ComUtil.getId();
				cbbTabColIndex.setId(id);
				cbbTabColIndex.setTableId(cbbTabColumns.getTableId());
				cbbTabColIndex.setColumnId(cbbTabColumns.getId());
				cbbTabColIndex.setDeptId(deptId);
				cbbTabColIndex.setOrgId(orgId);
				cbbTabColIndex.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColIndex, OpType.insert);
				hibernateDao.save(cbbTabColIndex);
				SysLogUtil.log(cbbTabColIndex, null, OpType.insert, OpResult.success);
				if ("1".equals(indexType) && "Y".equals(isTrueTable)) {
					// 添加ORCALE一般索引
					String sql = "CREATE INDEX " + indexName + " ON " + tableName + " (" + cbbTabColumns.getColName() + ")";
					jdbcAvicit.getJdbcTemplate().execute(sql);
					jdbcAvicit.getJdbcTemplate().execute("commit");
					SysLogUtil.log("库结构定义模块", "创建列索引记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
				}
			}
			// 4.复制分类搜索信息(search_order,remark)
			String searchSql = "SELECT T.SEARCH_ORDER,T.REMARK FROM CBB_TAB_COL_SEARCH T WHERE T.TABLE_ID = '" + cbbTabColumnsCopyed.getTableId() + "' AND T.COLUMN_ID = '" + cbbTabColumnsCopyed.getId() + "'";
			List<Object[]> searchList = this.hibernateDao.findBySQL(searchSql);
			for (int i = 0; i < searchList.size(); i++) {
				CbbTabColSearch cbbTabColSearch = new CbbTabColSearch();
				cbbTabColSearch.setSearchOrder(new BigDecimal(searchList.get(i)[0].toString()));
				cbbTabColSearch.setRemark(searchList.get(i)[1] == null ? "" : searchList.get(i)[1].toString());
				String id = ComUtil.getId();
				cbbTabColSearch.setId(id);
				cbbTabColSearch.setTableId(cbbTabColumns.getTableId());
				cbbTabColSearch.setColumnId(cbbTabColumns.getId());
				cbbTabColSearch.setDeptId(deptId);
				cbbTabColSearch.setOrgId(orgId);
				cbbTabColSearch.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColSearch, OpType.insert);
				hibernateDao.save(cbbTabColSearch);
				SysLogUtil.log(cbbTabColSearch, null, OpType.insert, OpResult.success);
			}
			// 5.复制排序信息(sort_order,sort_code,remark)
			String sortSql = "SELECT T.SORT_ORDER,T.SORT_CODE,T.REMARK FROM CBB_TAB_COL_SORT T WHERE T.COLUMN_ID = '" + cbbTabColumnsCopyed.getId() + "'";
			List<Object[]> sortList = this.hibernateDao.findBySQL(sortSql);
			for (int i = 0; i < sortList.size(); i++) {
				CbbTabColSort cbbTabColSort = new CbbTabColSort();
				cbbTabColSort.setSortOrder(new BigDecimal(sortList.get(i)[0].toString()));
				cbbTabColSort.setSortCode(sortList.get(i)[1].toString());
				cbbTabColSort.setRemark(sortList.get(i)[2] == null ? "" : sortList.get(i)[2].toString());
				String id = ComUtil.getId();
				cbbTabColSort.setId(id);
				cbbTabColSort.setTableId(cbbTabColumns.getTableId());
				cbbTabColSort.setColumnId(cbbTabColumns.getId());
				cbbTabColSort.setDeptId(deptId);
				cbbTabColSort.setOrgId(orgId);
				cbbTabColSort.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColSort, OpType.insert);
				hibernateDao.save(cbbTabColSort);
				SysLogUtil.log(cbbTabColSort, null, OpType.insert, OpResult.success);
			}
			// 6.复制form表单信息
			List<String> formIdList = getFormIdByTableIdByFormConfig(sysId, tableId);// formId
			String formId = "";
			if (formIdList.size() > 0) {
				formId = formIdList.get(0);
			}
			if (!"".equals(formId)) {
				// 根据formId和columnId判断该字段是否已经存在配置信息
				boolean hasConfig = billDefineManagerService.getformConfigByFormIdAndColId(formId, cid);
				if (!hasConfig) {
					String formConfigId = ComUtil.getId();
					CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
					cbbTabFormConfig.setId(formConfigId);
					cbbTabFormConfig.setFormId(formId);
					cbbTabFormConfig.setColumnId(cid);
					BigDecimal formVertical = new BigDecimal(1);
					cbbTabFormConfig.setFormVertical(formVertical);
					BigDecimal formHorizontal = new BigDecimal(1);
					cbbTabFormConfig.setFormHorizontal(formHorizontal);
					cbbTabFormConfig.setOrgId(orgId);
					cbbTabFormConfig.setDeptId(deptId);
					cbbTabFormConfig.setSysId(sysId);
					cbbTabFormConfig.setAttribute11(cbbTabColumns.getColOrder());
					PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
					hibernateDao.save(cbbTabFormConfig);
					SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
				}
			}
			// 7、同步节点著录定义配置信息
			// Map<String, Object> tabNodeRecordParam = new HashMap<String,
			// Object>();
			// tabNodeRecordParam.put("sysId", sysId);
			// tabNodeRecordParam.put("orgId", orgId);
			// tabNodeRecordParam.put("deptId", deptId);
			// tabNodeRecordParam.put("tableId", tableId);
			// tabNodeRecordParam.put("obj", cbbTabColumns);
			// this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
		}
	}

	/**
	 * 验证字段是否重名
	 */
	@Override
	public boolean checkField(String id, String sysId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		boolean flag = false;
		CbbTempletField cbbTempletField = this.getCommTempletFieldById(id);
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*)\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.COL_NAME = '" + cbbTempletField.getColName() + "'\n");
		sbSql.append("   AND T.TABLE_ID = '" + tableId + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		int num = Integer.parseInt(String.valueOf(list.get(0)));
		if (num > 0) {
			flag = true;
		}
		return flag;
	}

	/***
	 * 复制库结构字段时验证字段是否重复
	 *
	 * @param id
	 * @param sysId
	 * @param tableName
	 * @return
	 * @throws Exception
	 */
	public boolean checkCbbColumnsField(String id, String sysId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		boolean flag = false;
		CbbTabColumns cbbTabcolumns = getCbbTabColumnsById(id);
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*)\n");
		sbSql.append(" FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.COL_NAME = '" + cbbTabcolumns.getColName() + "'\n");
		sbSql.append(" AND T.TABLE_ID = '" + tableId + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		int num = Integer.parseInt(String.valueOf(list.get(0)));
		if (num > 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 根据模版代码获取模版ID
	 *
	 * @param templetInfoCode
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	public String getTempletIdByTempletCode(String templetInfoCode) throws Exception {
		String templetId = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID FROM CBB_TEMPLET_INFO T WHERE T.TEMP_CODE = '" + templetInfoCode + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		if (list.size() > 0) {
			templetId = String.valueOf(list.get(0));
		}
		return templetId;
	}

	/**
	 * 根据系统标识ID，表名，获取表ID
	 *
	 * @param sysId
	 * @param tableName
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public String getCbbTableId(String sysId, String tableName) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = "";
		String sql = "SELECT T.ID FROM CBB_TABLES T WHERE T.TABLE_NAME = '" + tableName + "' AND T.SYS_ID = '" + sysId + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		if (objList != null && objList.size() > 0) {
			tableId = String.valueOf(objList.get(0));
		}
		return tableId;
	}

	/**
	 * 根据tableId、nodeId获取tabNodeId（文件类型取‘个人文件’‘部门文件’节点ID作为tabNodeId）
	 *
	 * @param sysId
	 *            必填
	 * @param tableId
	 *            必填
	 * @param nodeId
	 * @return
	 * @throws Exception
	 * @throws
	 */
	@Override
	public List<Object> getCbbTabNodeIdByTableId(String sysId, String tableId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Object> objList = new ArrayList<Object>();
		// 1、根据tableId查找nodeId
		String nodeIdSql = "SELECT T.NODE_ID FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "'";
		List<String> nodeIdLsit = this.hibernateDao.findBySQL(nodeIdSql);
		if (nodeIdLsit.size() > 0) {
			String parentIds = ""; // nodeID，多个时以英文逗号分割
			for (String str : nodeIdLsit) {
				parentIds = parentIds + "," + str;
			}
			if (!"".equals(parentIds)) {
				parentIds = parentIds.substring(1);
			}
			// 2、将nodeId作为parentId查找lantop_archive节点
			// 调用rest服务
//			CbbArchiveClassRestClient cbbArchiveClassRestClient = new CbbArchiveClassRestClient("/api/im/lantop/basic/archiveclass");
//			ResponseMsg<String> responseMsg = RestClient.doPost(cbbArchiveClassRestClient.getRestUrl("/getNodeIdByParentId/v1"), parentIds, new GenericType<ResponseMsg<String>>() {
//			});
			ResponseMsg<String> responseMsg = RestClient.doPost("/getNodeIdByParentId/v1", parentIds,new GenericType<ResponseMsg<String>>() {
			});
			if (responseMsg.getRetCode().equals(ResponseStatus.HTTP_OK)) {
				String tabNodeIds = responseMsg.getResponseBody(); // tabnodeId，多个以英文逗号分割
				if (null != tabNodeIds && !"".equals(tabNodeIds) && !"null".equals(tabNodeIds)) {
					// 文件类型，获取rest服务返回结果
					String[] tabNodeIdArr = tabNodeIds.split(",");
					for (String tabNodeId : tabNodeIdArr) {
						objList.add(tabNodeId);
					}
				} else {
					// 非文件类型，通过sql查找tabNodeId
					StringBuffer sbSql = new StringBuffer();
					sbSql.append("SELECT T.ID\n");
					sbSql.append("  FROM CBB_TAB_NODE T\n");
					sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
					sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
					if (null != nodeId && !"".equals(nodeId) && !"null".equals(nodeId)) {
						sbSql.append(" AND T.NODE_ID = '" + nodeId + "'");
					}
					objList = hibernateDao.findBySQL(sbSql.toString());
				}
			} /*
			 * else { throw new RuntimeException(responseMsg.getErrorDesc()); }
			 */
		}
		return objList;
	}

	/**
	 * 通过tableId获取tabNodeId用于表单配置信息
	 *
	 * @param sysId
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             List<String>
	 * @author 郭亮
	 */
	public List<String> getCbbTabNodeIdByTableIdByFormConfig(String sysId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<String> objList = new ArrayList<String>();
		// 1、根据tableId查找nodeId
		String nodeIdSql = "SELECT T.NODE_ID FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "'";
		List<String> nodeIdLsit = this.hibernateDao.findBySQL(nodeIdSql);
		for (int i = 0; i < nodeIdLsit.size(); i++) {
			String nd = nodeIdLsit.get(i);
			// 非文件类型，通过sql查找tabNodeId
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("SELECT T.ID\n");
			sbSql.append("  FROM CBB_TAB_NODE T\n");
			sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
			sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
			sbSql.append(" AND T.NODE_ID = '" + nd + "'");
			List<Object> objl = hibernateDao.findBySQL(sbSql.toString());
			for (int j = 0; j < objl.size(); j++) {
				objList.add(String.valueOf(objl.get(j)));
			}
		}
		return objList;
	}

	/**
	 * 根据tableId查询tabNodeId
	 *
	 * @param sysId
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             List<Object>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public String getCbbTabNodeId(String sysId, String nodeId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String nid = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID\n");
		sbSql.append("  FROM CBB_TAB_NODE T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   AND T.NODE_ID = '" + nodeId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			nid = String.valueOf(objList.get(0));
		}
		return nid;
	}

	/**
	 * 根据表信息ID获取表信息
	 *
	 * @param id
	 * @return CbbTables
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public CbbTables getCbbTablesById(String id) {
		CbbTables h = (CbbTables) hibernateDao.getSession().get(CbbTables.class, id);
		return h;
	}

	/**
	 * 根据索引ID获取索引数据
	 *
	 * @param id
	 * @return CbbTabColIndex
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public CbbTabColIndex getCbbTabColIndexById(String id) {
		CbbTabColIndex h = (CbbTabColIndex) hibernateDao.getSession().get(CbbTabColIndex.class, id);
		return h;
	}

	/**
	 * 根据表信息ID获取表信息
	 */
	public CbbTabNode getCbbTabNodeById(String id) {
		CbbTabNode h = (CbbTabNode) hibernateDao.getSession().get(CbbTabNode.class, id);
		return h;
	}

	/**
	 * 删除排序字段
	 *
	 * @param id
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void deleteCbbTabSort(String id) throws Exception {
		try {
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("DELETE FROM CBB_TAB_COL_SORT T WHERE T.ID = '" + id + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
			SysLogUtil.log("库结构定义模块", "删除排序字段记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除分类检索
	 *
	 * @param id
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void deleteCbbTabSearch(String id) throws Exception {
		try {
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("DELETE FROM CBB_TAB_COL_SEARCH T WHERE T.ID = '" + id + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
			SysLogUtil.log("库结构定义模块", "删除分类检索记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除系统通用代码信息
	 */
	@Override
	public void deleteCbbSysCodeRecord(String colId) throws Exception {
		try {
			String sql = "DELETE FROM CBB_TAB_COL_SYS_CODE T WHERE  T.ID = '" + colId + "'";
			this.jdbcAvicit.getJdbcTemplate().execute(sql);
			SysLogUtil.log("库结构定义模块", "删除系统通用代码记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取列代码信息
	 */
	@Override
	public Page<Map<String, Object>> getPageCodeDetailList(Paging<CbbTempletCode> page, Map<String, Object> parameter) throws Exception {
		String cid = (String) parameter.get("cid");
		String sysId = (String) parameter.get("sysId");
		String tableName = (String) parameter.get("tableName");
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", parameter.get("orgId"));
		String tid = getTableIdBysysIdAndTableName(sysId, tableName, param);
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,\n");
		sbSql.append("       T.TABLE_ID,\n");
		sbSql.append("       T.COLUMN_ID,\n");
		sbSql.append("       T.CODE_ORDER,\n");
		sbSql.append("       T.LOOKUP_NAME,\n");
		sbSql.append("       T.LOOKUP_CODE,\n");
		sbSql.append("       T.CODE_IS_VALID,\n");
		sbSql.append("       T.CTYPE,\n");
		sbSql.append("       T.CREATED_BY,\n");
		sbSql.append("       T.CREATION_DATE,\n");
		sbSql.append("       T.LAST_UPDATED_BY,\n");
		sbSql.append("       T.LAST_UPDATE_DATE,\n");
		sbSql.append("       T.LAST_UPDATE_IP\n");
		sbSql.append("  FROM CBB_TAB_LOOKUP_V T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tid + "'\n");
		sbSql.append("   AND T.COLUMN_ID = '" + cid + "'");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取节点著录定义列表信息
	 */
	@Override
	public Page<Map<String, Object>> getPageNodeRecordList(Paging<CbbTabColumns> page, Map<String, Object> parameter) {
		String tabNodeId = (String) parameter.get("tabNodeId");
		String tableId = (String) parameter.get("tableId");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,\n");
		sbSql.append("       T.COL_NAME,\n");
		sbSql.append("       T.COL_LABEL,\n");
		sbSql.append("       T.COL_TYPE,\n");
		sbSql.append("       T.COL_LENGTH,\n");
		sbSql.append("       T.COL_DECIMAL,\n");
		sbSql.append("       T.COL_IS_SYS,\n");
		sbSql.append("       T.COL_IS_MUST,\n");
		sbSql.append("       CTNR.COL_ORDER,\n");
		sbSql.append("       CTNR.COL_IS_VISIBLE,\n");
		sbSql.append("       CTNR.COL_IS_TAB_VISIBLE,\n");
		sbSql.append("       CTNR.COL_IS_DETAIL,\n");
		sbSql.append("       CTNR.COL_IS_SEARCH,\n");
		sbSql.append("       CTNR.REMARK,\n");
		sbSql.append("       CTNR.TAB_NODE_ID,\n");
		sbSql.append("       CTNR.ID AS TAB_NODE_RECORD_ID\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("  LEFT JOIN CBB_TAB_NODE_RECORD CTNR\n");
		sbSql.append("    ON CTNR.COLUMN_ID = T.ID\n");
		sbSql.append(" WHERE T.COL_IS_DISPLAY = 'Y' AND CTNR.TAB_NODE_ID = '" + tabNodeId + "'\n");
		if (null != tableId && !"".equals(tableId) && !"null".equals(tableId)) {
			sbSql.append(" AND CTNR.TABLE_ID = '" + tableId + "'\n");
		}
		sbSql.append(" ORDER BY CTNR.COL_ORDER");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取排序主表信息
	 *
	 * @param page
	 * @param parameter
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Page<Map<String, Object>> getPageTabSortList(Paging<CbbTabColumns> page, Map<String, Object> parameter) throws Exception {
		String tableId = (String) parameter.get("tableId");
		String isTemplet = (String) parameter.get("isTemplet");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT CT.ID            AS TABLE_ID,\n");
		sbSql.append("         CTC.ID           AS COL_ID,\n");
		sbSql.append("         CTC.COL_ORDER,\n");
		sbSql.append("         CTC.COL_LABEL,\n");
		sbSql.append("         CTCS.SORT_CODE,\n");
		sbSql.append("         CTCS.SORT_ORDER,\n");
		sbSql.append("         CTC.COL_IS_DISPLAY,\n");
		sbSql.append("         CTC.COL_IS_SYS\n");
		sbSql.append("    FROM CBB_TABLES CT\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("      ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COL_SORT CTCS\n");
		sbSql.append("      ON CTCS.COLUMN_ID = CTC.ID\n");
		sbSql.append("   WHERE CT.ID = '" + tableId + "'\n");
		sbSql.append("     AND (CTC.COL_IS_SYS = 'N' OR CTC.COL_IS_DISPLAY = 'Y')\n");
		sbSql.append("   ORDER BY CTC.COL_ORDER,CTC.COL_NAME),\n");
		sbSql.append("T2 AS\n");
		sbSql.append(" (SELECT CT.ID            AS TABLE_ID,\n");
		sbSql.append("         CTC.ID           AS COL_ID,\n");
		sbSql.append("         CTC.COL_ORDER,\n");
		sbSql.append("         CTC.COL_LABEL,\n");
		sbSql.append("         CTCS.SORT_CODE,\n");
		sbSql.append("         CTCS.SORT_ORDER,\n");
		sbSql.append("         CTC.COL_IS_DISPLAY,\n");
		sbSql.append("         CTC.COL_IS_SYS\n");
		sbSql.append("    FROM CBB_TABLES CT\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("      ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COL_SORT CTCS\n");
		sbSql.append("      ON CTCS.COLUMN_ID = CTC.ID\n");
		sbSql.append("   WHERE CT.ID = '" + tableId + "'\n");
		sbSql.append("     AND CTC.COL_IS_SYS = 'Y'\n");
		sbSql.append("     AND CTC.COL_IS_DISPLAY = 'N'\n");
		sbSql.append("   ORDER BY CTC.COL_ORDER,CTC.COL_NAME),\n");
		sbSql.append("T3 AS\n");
		sbSql.append(" (SELECT T1.*\n");
		sbSql.append("    FROM T1\n");
		sbSql.append("  UNION ALL\n");
		sbSql.append("  SELECT T2.* FROM T2)\n");
		sbSql.append("SELECT T3.*\n");
		sbSql.append("  FROM T3\n");
		if ("N".equals(isTemplet)) {
			sbSql.append(" WHERE T3.COL_IS_DISPLAY = 'Y'");
		}
		// SanXiaFiles Create By Tangkun Start
		String inputWord = String.valueOf(parameter.get("inputWord"));
		if (inputWord != null && !"".equals(inputWord) && inputWord != "null") {
			sbSql.append(" AND T3.COL_LABEL like '%" + inputWord + "%'\n");
		}
		// SanXiaFiles Create By Tangkun End
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取排序子表信息
	 *
	 * @param page
	 * @param parameter
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Page<Map<String, Object>> getCbbTabColSortData(Paging<CbbTabColumns> page, Map<String, Object> parameter) throws Exception {
		String tableId = (String) parameter.get("tableId");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTCS.ID,\n");
		sbSql.append("       CTCS.TABLE_ID,\n");
		sbSql.append("       CTCS.COLUMN_ID,\n");
		sbSql.append("       CTC.COL_LABEL,\n");
		sbSql.append("       CTCS.SORT_ORDER,\n");
		sbSql.append("       CTCS.SORT_CODE\n");
		sbSql.append("  FROM CBB_TAB_COL_SORT CTCS\n");
		sbSql.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("    ON CTCS.COLUMN_ID = CTC.ID\n");
		sbSql.append("  LEFT JOIN CBB_TABLES CT\n");
		sbSql.append("    ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append(" WHERE CTCS.TABLE_ID = '" + tableId + "'");
		sbSql.append(" ORDER BY CTCS.SORT_ORDER");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取分类检索主表信息
	 *
	 * @param page
	 * @param parameter
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Page<Map<String, Object>> getPageTabSearchList(Paging<CbbTabColumns> page, Map<String, Object> parameter) throws Exception {
		String tableId = (String) parameter.get("tableId");
		String isTemplet = (String) parameter.get("isTemplet");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT CT.ID            AS TABLE_ID,\n");
		sbSql.append("         CTC.ID           AS COL_ID,\n");
		sbSql.append("         CTC.COL_ORDER,\n");
		sbSql.append("         CTC.COL_LABEL,\n");
		sbSql.append("         CTC.COL_IS_DISPLAY,\n");
		sbSql.append("         CTC.COL_IS_SYS,\n");
		sbSql.append("         CTC.COL_NAME\n");
		sbSql.append("    FROM CBB_TABLES CT\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("      ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append("   WHERE CT.ID = '" + tableId + "'\n");
		sbSql.append("     AND (CTC.COL_IS_SYS = 'N' OR CTC.COL_IS_DISPLAY = 'Y')\n");
		sbSql.append("   ORDER BY CTC.COL_ORDER,CTC.COL_NAME),\n");
		sbSql.append("T2 AS\n");
		sbSql.append(" (SELECT CT.ID            AS TABLE_ID,\n");
		sbSql.append("         CTC.ID           AS COL_ID,\n");
		sbSql.append("         CTC.COL_ORDER,\n");
		sbSql.append("         CTC.COL_LABEL,\n");
		sbSql.append("         CTC.COL_IS_DISPLAY,\n");
		sbSql.append("         CTC.COL_IS_SYS,\n");
		sbSql.append("         CTC.COL_NAME\n");
		sbSql.append("    FROM CBB_TABLES CT\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("      ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append("   WHERE CT.ID = '" + tableId + "'\n");
		sbSql.append("     AND CTC.COL_IS_SYS = 'Y'\n");
		sbSql.append("     AND CTC.COL_IS_DISPLAY = 'N'\n");
		sbSql.append("   ORDER BY CTC.COL_ORDER,CTC.COL_NAME),\n");
		sbSql.append("T3 AS\n");
		sbSql.append(" (SELECT T1.*\n");
		sbSql.append("    FROM T1\n");
		sbSql.append("  UNION ALL\n");
		sbSql.append("  SELECT T2.* FROM T2)\n");
		sbSql.append("SELECT T3.*\n");
		sbSql.append("  FROM T3\n");
		if ("N".equals(isTemplet)) {
			sbSql.append(" WHERE T3.COL_IS_DISPLAY = 'Y'");
		}
		// SanXiaFiles Create By Tangkun Start
		String inputWord = String.valueOf(parameter.get("inputWord"));
		if (inputWord != null && !"".equals(inputWord) && inputWord != "null") {
			sbSql.append(" AND T3.COL_LABEL like '%" + inputWord + "%'\n");
		}
		// SanXiaFiles Create By Tangkun End
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取分类检索子表信息
	 *
	 * @param page
	 * @param parameter
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Page<Map<String, Object>> getCbbTabColSearchData(Paging<CbbTabColumns> page, Map<String, Object> parameter) throws Exception {
		String tableId = (String) parameter.get("tableId");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTCS.ID,\n");
		sbSql.append("       CTCS.TABLE_ID,\n");
		sbSql.append("       CTCS.COLUMN_ID,\n");
		sbSql.append("       CTC.COL_LABEL,\n");
		sbSql.append("       CTCS.SEARCH_ORDER\n");
		sbSql.append("  FROM CBB_TAB_COL_SEARCH CTCS\n");
		sbSql.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("    ON CTCS.COLUMN_ID = CTC.ID\n");
		sbSql.append("  LEFT JOIN CBB_TABLES CT\n");
		sbSql.append("    ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append(" WHERE CTCS.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("    AND CTC.COL_IS_DISPLAY = 'Y'");
		sbSql.append(" ORDER BY CTCS.SEARCH_ORDER ");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取基本列信息(节点著录定义)
	 *
	 * @param page
	 * @param parameter
	 * @return Page<Map < String, Object>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Page<Map<String, Object>> getPageNodeRecordColList(Paging<CbbTabColumns> page, Map<String, Object> parameter) {
		String tableId = (String) parameter.get("tableId");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM CBB_TAB_COLUMNS T WHERE T.COL_IS_DISPLAY = 'Y' AND T.TABLE_ID = '" + tableId + "' ORDER BY T.COL_ORDER,T.COL_NAME");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 新增代码维护信息
	 *
	 * @param cbbTabColCode
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertTabColCode(CbbTabColCode cbbTabColCode) {
		String id = ComUtil.getId();
		cbbTabColCode.setId(id);
		PojoUtil.setSysProperties(cbbTabColCode, OpType.insert);
		hibernateDao.save(cbbTabColCode);
		SysLogUtil.log(cbbTabColCode, null, OpType.insert, OpResult.success);
	}

	/**
	 * 新增系统代码维护信息
	 *
	 * @param cbbTabColCode
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertTabColSysCode(CbbTabColSysCode cbbTabColSysCode) {
		String id = ComUtil.getId();
		cbbTabColSysCode.setId(id);
		PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
		hibernateDao.save(cbbTabColSysCode);
		SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
	}

	/**
	 * 批量新增代码维护信息
	 *
	 * @param insertData
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertTabColCodeByJson(String insertData, String tableId, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		JSONArray ja = JSONArray.fromObject(insertData);
		for (int i = 0; i < ja.size(); i++) {
			JSONObject jj = JSONObject.fromObject(ja.get(i));
			int codeOrder = Integer.parseInt(jj.getString("CODE_ORDER"));
			BigDecimal bOrder = new BigDecimal(codeOrder);
			String columnId = jj.getString("COLUMN_ID");
			String lookupName = jj.getString("LOOKUP_NAME");
			String lookupCode = jj.getString("LOOKUP_CODE");
			String codeIsValid = jj.getString("CODE_IS_VALID");
			CbbTabColCode cbbTabColCode = new CbbTabColCode();
			cbbTabColCode.setTableId(tableId);
			cbbTabColCode.setColumnId(columnId);
			cbbTabColCode.setCodeOrder(bOrder);
			cbbTabColCode.setLookupName(lookupName);
			cbbTabColCode.setLookupCode(lookupCode);
			cbbTabColCode.setCodeIsValid(codeIsValid);
			cbbTabColCode.setOrgId(SessionHelper.getCurrentOrgId());
			cbbTabColCode.setDeptId(SessionHelper.getCurrentDeptId());
			cbbTabColCode.setSysId(sysId);
			insertTabColCode(cbbTabColCode);// 调用新增方法
		}
	}

	/**
	 * 新增生成方式规则信息
	 *
	 * @param cbbTabFormSelect
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertCbbTabFormSelect(CbbTabFormSelect cbbTabFormSelect) {
		String id = ComUtil.getId();
		cbbTabFormSelect.setId(id);
		PojoUtil.setSysProperties(cbbTabFormSelect, OpType.insert);
		hibernateDao.save(cbbTabFormSelect);
		SysLogUtil.log(cbbTabFormSelect, null, OpType.insert, OpResult.success);
	}

	/**
	 * 新增字段排序信息
	 *
	 * @param cbbTabColSort
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertCbbTabColSorte(CbbTabColSort cbbTabColSort) {
		String id = ComUtil.getId();
		cbbTabColSort.setId(id);
		PojoUtil.setSysProperties(cbbTabColSort, OpType.insert);
		hibernateDao.save(cbbTabColSort);
		SysLogUtil.log(cbbTabColSort, null, OpType.insert, OpResult.success);
	}

	/**
	 * 新增分类检索信息
	 *
	 * @param cbbTabColSearch
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertCbbTabColSearch(CbbTabColSearch cbbTabColSearch) throws Exception {
		String id = ComUtil.getId();
		cbbTabColSearch.setId(id);
		PojoUtil.setSysProperties(cbbTabColSearch, OpType.insert);
		hibernateDao.save(cbbTabColSearch);
		SysLogUtil.log(cbbTabColSearch, null, OpType.insert, OpResult.success);
	}

	/**
	 * 新增系统通用代码信息
	 */
	@Override
	public void insertSysCode(String cid, String tid, String fid, String sysId, String orgId, String deptId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		try {
			// 删除存在的系统通用代码数据
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("DELETE FROM CBB_TAB_COL_SYS_CODE T WHERE T.COLUMN_ID = '" + fid + "'");
			jdbcTemplate.update(sbSql.toString());
			SysLogUtil.log("库结构定义模块", "删除系统通用代码记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 新增系统通用代码数据
		CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
		String id = ComUtil.getId();
		cbbTabColSysCode.setId(id);
		cbbTabColSysCode.setSysLookupId(cid);
		cbbTabColSysCode.setTableId(tid);
		cbbTabColSysCode.setColumnId(fid);
		cbbTabColSysCode.setOrgId(orgId);
		cbbTabColSysCode.setDeptId(deptId);
		cbbTabColSysCode.setSysId(sysId);
		PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
		hibernateDao.save(cbbTabColSysCode);
		SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
	}

	/**
	 * 验证菜单路径是否存在
	 *
	 * @param path
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public boolean checkMenuPath(String path) throws  Exception {
		boolean flag = false;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*) FROM SYS_MENU T WHERE T.URL = '" + path + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			int num = Integer.parseInt(String.valueOf(objList.get(0)));
			if (num != 0) {
				flag = true;
			}
		}
		return flag;
	}

	/**
	 * 验证是否节点著录表存在数据
	 *
	 * @param path
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public boolean checkNodeRecord(String tabNodeId, String tableId) {
		boolean flag = false;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*) FROM CBB_TAB_NODE_RECORD T WHERE T.TAB_NODE_ID = '" + tabNodeId + "' AND T.TABLE_ID = '" + tableId + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			int num = Integer.parseInt(String.valueOf(objList.get(0)));
			if (num != 0) {
				flag = true;
			}
		}
		return flag;
	}

	/**
	 * 创建菜单
	 *
	 * @param path
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 *            void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void createMenu(String path, String sysId, String tableName, Map<String, Object> param) throws Exception{
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase();// 将参数转换为大写
		// 查询该系统的主菜单ID
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID FROM SYS_MENU T WHERE T.CODE = '" + sysId + "_MENU'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		String pid = "";
		if (objList != null && objList.size() > 0) {
			pid = String.valueOf(objList.get(0));
		}
		if (!"".equals(pid)) {
			// 添加菜单语言数据
			String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
			CbbTables cbbTables = getCbbTablesById(tableId);
			// 添加菜单基本数据
			String mid = ComUtil.getId();
			SysMenu sysMenu = new SysMenu();
			sysMenu.setId(mid);
			sysMenu.setUrl(path);
			sysMenu.setSysApplicationId("1");
			sysMenu.setCode(cbbTables.getTableName() + "_MENU");
			sysMenu.setParentId(pid);
			BigDecimal colOrder = new BigDecimal(0);
			sysMenu.setOrderBy(colOrder);
			sysMenu.setType("1");
			sysMenu.setScroll("0");
			sysMenu.setIsclose("0");
			sysMenu.setStatus("1");
			sysMenu.setIsShowTitle("1");
			sysMenu.setIsDrag("1");
			sysMenu.setMenuGroup("1");
			PojoUtil.setSysProperties(sysMenu, OpType.insert);
			hibernateDao.save(sysMenu);
			// 添加菜单语言数据
			SysMenuTl sysMenuTl = new SysMenuTl();
			sysMenuTl.setId(ComUtil.getId());
			sysMenuTl.setSysMenuId(mid);
			sysMenuTl.setSysLanguageCode("zh_CN");
			sysMenuTl.setName(cbbTables.getTableTitle() + "菜单");
			PojoUtil.setSysProperties(sysMenuTl, OpType.insert);
			hibernateDao.save(sysMenuTl);
			// 添加菜单资源数据
			// 查询主菜单的资源ID
			StringBuffer sbSqlId = new StringBuffer();
			sbSqlId.append("SELECT T.ID\n");
			sbSqlId.append("  FROM SYS_RESOURCE T\n");
			sbSqlId.append("  LEFT JOIN SYS_MENU_TL SMT\n");
			sbSqlId.append("    ON SMT.NAME = T.KEY\n");
			sbSqlId.append(" WHERE SMT.SYS_MENU_ID = '" + pid + "'");
			List<Object> objListId = hibernateDao.findBySQL(sbSqlId.toString());
			String sid = "";// 资源表父Id
			if (objListId != null && objListId.size() > 0) {
				sid = String.valueOf(objListId.get(0));
			}
			SysResource sysResource = new SysResource();
			sysResource.setId(mid);
			sysResource.setKey(cbbTables.getTableTitle() + "菜单");
			sysResource.setValue(path);
			sysResource.setParentId(sid);
			sysResource.setSysApplicationId("1");
			PojoUtil.setSysProperties(sysResource, OpType.insert);
			hibernateDao.save(sysResource);
		}
	}

	/**
	 * 验证此真实值是否存在
	 *
	 * @param id
	 * @param columnId
	 * @param lookupCode
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public boolean checkCode(String columnId, String lookupCode, String id) {
		boolean a = false;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*)\n");
		sbSql.append("  FROM CBB_TAB_COL_CODE T\n");
		sbSql.append("  LEFT JOIN CBB_TAB_COL_SYS_CODE CTCSC\n");
		sbSql.append("    ON CTCSC.COLUMN_ID = T.COLUMN_ID\n");
		sbSql.append("  LEFT JOIN CBB_LOOKUP_V CLV\n");
		sbSql.append("    ON CLV.ID = CTCSC.SYS_LOOKUP_ID\n");
		sbSql.append(" WHERE (T.LOOKUP_CODE = '" + lookupCode + "' \n");
		sbSql.append("   OR CLV.LOOKUP_CODE = '" + lookupCode + "')");
		sbSql.append("   AND T.COLUMN_ID = '" + columnId + "'\n");
		if (!"".equals(id)) {
			sbSql.append("   AND T.ID <> '" + id + "'\n");
		}
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		int num = 0;
		if (objList != null && objList.size() > 0) {
			num = Integer.parseInt(String.valueOf(objList.get(0)));
		}
		if (num > 0) {
			a = true;
		}
		return a;
	}

	/**
	 * 判断该表是否有值
	 *
	 * @param tableId
	 * @param cid
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public boolean checkColIsMust(String tableId) throws Exception {
		boolean a = true;
		CbbTables cbbTables = getCbbTablesById(tableId);
		String sql = "SELECT COUNT(*) FROM " + cbbTables.getTableName();
		List<Object> objList = hibernateDao.findBySQL(sql);
		if (objList.size() > 0) {
			int count = Integer.parseInt(String.valueOf(objList.get(0)));
			if (count > 0) {
				a = false;
			}
		}
		return a;
	}

	/**
	 * 导出结构数据
	 *
	 * @param headValue
	 * @param head
	 * @param data
	 * @param out
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 郭量
	 */
	@Override
	public void exportData(List<String> headValue, List<String> head, List<Map<String, Object>> data, ByteArrayOutputStream out) throws Exception {
		workbook = new HSSFWorkbook();
		this.headStyle = this.workbook.createCellStyle();
		headStyle.setBorderBottom(CellStyle.BORDER_THIN);
		headStyle.setBorderLeft(CellStyle.BORDER_THIN);
		headStyle.setBorderRight(CellStyle.BORDER_THIN);
		headStyle.setBorderTop(CellStyle.BORDER_THIN);
		headStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
		headStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
		headStyle.setAlignment(CellStyle.ALIGN_CENTER);
		HSSFFont headfont = workbook.createFont();
		// 设置头部字体为宋体
		headfont.setFontName("宋体");
		// 粗体
		headfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		headfont.setFontHeightInPoints((short) 11);
		// 单元格样式使用字体
		this.headStyle.setFont(headfont);
		HSSFFont datafont = workbook.createFont();
		this.stringstyle = this.workbook.createCellStyle();
		stringstyle.setBorderBottom(CellStyle.BORDER_THIN);
		stringstyle.setBorderLeft(CellStyle.BORDER_THIN);
		stringstyle.setBorderRight(CellStyle.BORDER_THIN);
		stringstyle.setBorderTop(CellStyle.BORDER_THIN);
		stringstyle.setAlignment(CellStyle.ALIGN_CENTER);
		// 单元格样式使用字体
		stringstyle.setFont(datafont);
		sheet = workbook.createSheet();
		sheet.setDefaultColumnWidth(16);
		// 当前行标示
		int currentRow = 0;
		row = sheet.createRow(currentRow);
		for (int i = 0; i < headValue.size(); i++) {
			cell = row.createCell(i);
			cell.setCellType(Cell.CELL_TYPE_STRING);
			cell.setCellValue(headValue.get(i).toString());
			cell.setCellStyle(headStyle);
		}
		currentRow++;
		// 循环遍历数据集合增加数据行
		for (int i = 0; i < data.size(); i++) {
			// 创建数据行
			row = sheet.createRow(currentRow);
			// 设置数据行中的列
			for (int j = 0; j < head.size(); j++) {
				// 创建列
				cell = row.createCell(j);
				// 获取一个对象
				Map<String, Object> sigleData = data.get(i);
				// 设置列属性和值
				cell.setCellType(Cell.CELL_TYPE_STRING);
				cell.setCellStyle(stringstyle);
				// 填值时做对应的转换
				String value = sigleData.get(head.get(j)) == null ? "" : sigleData.get(head.get(j)) + "";
				if ("string".equals(value)) {
					value = "字符串";
				} else if ("integer".equals(value)) {
					value = "整型";
				} else if ("float".equals(value)) {
					value = "浮点型";
				} else if ("date".equals(value)) {
					value = "日期时间型";
				} else if ("blob".equals(value)) {
					value = "BLOB";
				} else if ("clob".equals(value)) {
					value = "CLOB";
				} else if ("Y".equals(value)) {
					value = "是";
				} else if ("N".equals(value)) {
					value = "否";
				}
				cell.setCellValue(value);
			}
			// 下一行
			currentRow++;
		}
		workbook.write(out);
		out.flush();
	}

	/**
	 * 构造文件名
	 */
	@Override
	public String getFileName(String tableId) {
		String sql = "select t.table_title from cbb_tables t where t.id='" + tableId + "'";
		List<String> fileNames = hibernateDao.findBySQL(sql);
		if (fileNames.size() != 0 && fileNames != null) {
			return fileNames.get(0) + "";
		}
		return "";
	}

	/***
	 * 导出结构模板
	 *
	 * @param headValue
	 *            标题行值集合
	 * @param out
	 *            输出流对象
	 * @throws
	 */
	@Override
	public void exportExcelModule(List<String> headValue, ByteArrayOutputStream out) throws Exception {
		workbook = new HSSFWorkbook();
		this.headStyle = this.workbook.createCellStyle();
		headStyle.setBorderBottom(CellStyle.BORDER_THIN);
		headStyle.setBorderLeft(CellStyle.BORDER_THIN);
		headStyle.setBorderRight(CellStyle.BORDER_THIN);
		headStyle.setBorderTop(CellStyle.BORDER_THIN);
		headStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
		headStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
		headStyle.setAlignment(CellStyle.ALIGN_CENTER);
		HSSFFont headfont = workbook.createFont();
		// 设置头部字体为宋体
		headfont.setFontName("宋体");
		// 粗体
		headfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		headfont.setFontHeightInPoints((short) 11);
		// 单元格样式使用字体
		this.headStyle.setFont(headfont);
		sheet = workbook.createSheet();
		sheet.setDefaultColumnWidth(16);
		// 当前行标示
		int currentRow = 0;
		row = sheet.createRow(currentRow);
		for (int i = 0; i < headValue.size(); i++) {
			cell = row.createCell(i);
			cell.setCellType(Cell.CELL_TYPE_STRING);
			cell.setCellValue(headValue.get(i) + "");
			cell.setCellStyle(headStyle);
		}
		currentRow++;
		workbook.write(out);
		out.flush();
	}

	/**
	 * 将excel中的一行数据添加到数据表中
	 *
	 * @param cbbTabColumns
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @param orgId
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	public void insertCbbTabColumnsFromExel(CbbTabColumns cbbTabColumns, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId, String loginUserId, String loginIp, String isTrueTable) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		// 查询tableId
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
		String cid = ComUtil.getId();
		cbbTabColumns.setId(cid);
		cbbTabColumns.setTableId(tableId);
		cbbTabColumns.setSysId(sysId);
		cbbTabColumns.setOrgId(orgId);
		cbbTabColumns.setDeptId(deptId);
		cbbTabColumns.setCreatedBy(loginUserId);
		cbbTabColumns.setLastUpdatedBy(loginUserId);
		cbbTabColumns.setLastUpdateIp(loginIp);
		// 实体表已经存在的情况下,新增字段都是可为空的
		insertCbbTabColumus(cbbTabColumns);
		if ("Y".equals(isTrueTable)) {// 如果为真实表
			// 查询SYSID及组织ID，获取所对应的用户名
			List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
			String dbUser = "";// 用户名
			if (listConn.size() > 0) {
				Map<String, Object> connmap = listConn.get(0);
				dbUser = String.valueOf(connmap.get("DB_USER"));
			} else {
				throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
			}
			// 给实体表新增字段
			String colType = "";
			if (cbbTabColumns.getColType().equals("string")) {
				colType = "varchar2(" + (null == cbbTabColumns.getColLength() ? "128" : cbbTabColumns.getColLength()) + ")";
			} else if (cbbTabColumns.getColType().equals("integer")) {
				colType = "NUMBER";
				if (null != cbbTabColumns.getColLength()) {
					colType = colType + "(" + cbbTabColumns.getColLength() + ")";
				}
			} else if (cbbTabColumns.getColType().equals("date")) {
				colType = "DATE";
			} else if (cbbTabColumns.getColType().equals("float")) {
				colType = "NUMBER";
				if (cbbTabColumns.getColLength() != null) {
					colType = colType + "(" + cbbTabColumns.getColLength() + ",";
				} else {
					colType = colType + "(16,";
				}
				colType = colType + cbbTabColumns.getColDecimal() + ")";
			} else if (cbbTabColumns.getColType().equals("blob")) {
				colType = "BLOB";
			} else if (cbbTabColumns.getColType().equals("clob")) {
				colType = "CLOB";
			}
			try {
				String addCol = "ALTER TABLE " + dbUser + "." + tableName + " add " + cbbTabColumns.getColName() + " " + colType;
				this.jdbcAvicit.getJdbcTemplate().execute(addCol);
				this.jdbcAvicit.getJdbcTemplate().execute("commit");
				SysLogUtil.log("库结构定义模块", "新增列(实体表)记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
				// 给此字段增加注释
				addCol = "COMMENT ON COLUMN " + tableName + "." + cbbTabColumns.getColName() + "\n" + "  is '" + cbbTabColumns.getColLabel() + "'";
				this.jdbcAvicit.getJdbcTemplate().execute(addCol);
				this.jdbcAvicit.getJdbcTemplate().execute("commit");
				SysLogUtil.log("库结构定义模块", "新增列(实体表)记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
			} catch (Exception e) {
				e.printStackTrace();
				// 回滚添加列的数据
				CbbTabColumns cbbTabColumnsTemp = new CbbTabColumns();
				cbbTabColumnsTemp = getCbbTabColumnsById(cid);
				String mes = "字段【" + cbbTabColumns.getColLabel() + "】已经存在，请修改！";
				deleteCbbTabColumnsById(cbbTabColumnsTemp);
				throw new Exception(mes);
			}
		}
		// 给表单配置信息表添加数据
		List<String> formIdList = getFormIdByTableIdByFormConfig(sysId, tableId);// formId
		String formId = "";
		if (formIdList.size() > 0) {
			formId = formIdList.get(0);
		}
		if (!"".equals(formId)) {
			// 根据formId和columnId判断该字段是否已经存在配置信息
			boolean hasConfig = billDefineManagerService.getformConfigByFormIdAndColId(formId, cid);
			if (!hasConfig) {
				String formConfigId = ComUtil.getId();
				CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
				cbbTabFormConfig.setId(formConfigId);
				cbbTabFormConfig.setFormId(formId);
				cbbTabFormConfig.setColumnId(cid);
				BigDecimal formVertical = new BigDecimal(1);
				cbbTabFormConfig.setFormVertical(formVertical);
				BigDecimal formHorizontal = new BigDecimal(1);
				cbbTabFormConfig.setFormHorizontal(formHorizontal);
				cbbTabFormConfig.setOrgId(orgId);
				cbbTabFormConfig.setDeptId(deptId);
				cbbTabFormConfig.setSysId(sysId);
				cbbTabFormConfig.setAttribute11(cbbTabColumns.getColOrder());
				PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
				hibernateDao.save(cbbTabFormConfig);
				SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
			}
		}
		// 2同步节点著录定义配置信息
		// Map<String, Object> tabNodeRecordParam = new HashMap<String,
		// Object>();
		// tabNodeRecordParam.put("sysId", sysId);
		// tabNodeRecordParam.put("orgId", orgId);
		// tabNodeRecordParam.put("deptId", deptId);
		// tabNodeRecordParam.put("tableId", tableId);
		// tabNodeRecordParam.put("obj", cbbTabColumns);
		// this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
	}

	/**
	 * 将excel文件中的数据添加到数据库表中
	 *
	 * @param datas
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @param orgId
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertFromExcel(Vector<Vector<String>> datas, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId, String loginUserId, String loginIp, String isTrueTable) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		for (int j = 1; j < datas.size(); j++) {
			Vector<String> row = datas.get(j);
			String label = row.get(0);// 中文名
			String name = row.get(1);// 字段名
			String type = row.get(2).toUpperCase();// 字段类型
			String length = row.get(3).replace(".0", "");// 长度
			String decimal = row.get(4).replace(".0", "");// 小数位数
			// String colIsSys = row.get(5);// 系统字段（目前后台死值：否）
			String colIsDisplay = row.get(6);// 是否可见
			String isMust = row.get(7);// 是否必著
			String order = row.get(8).replace(".0", "");// 顺序
			String remark = row.get(9).replace(".0", "");// 备注
			CbbTabColumns cbbTabColumns = new CbbTabColumns();
			cbbTabColumns.setColName(name);
			cbbTabColumns.setColLabel(label);
			if (type.equals("字符串")) {
				cbbTabColumns.setColType("string");
			} else if (type.equals("整型")) {
				cbbTabColumns.setColType("integer");
			} else if (type.equals("浮点型")) {
				cbbTabColumns.setColType("float");
			} else if (type.equals("日期时间型")) {
				cbbTabColumns.setColType("date");
			} else if (type.equals("BLOB")) {
				cbbTabColumns.setColType("blob");
			} else if (type.equals("CLOB")) {
				cbbTabColumns.setColType("clob");
			}
			if (!length.equals("")) {
				cbbTabColumns.setColLength(new BigDecimal(Integer.parseInt(length)));
			}
			if (!decimal.equals("")) {
				cbbTabColumns.setColDecimal(new BigDecimal(Integer.parseInt(decimal)));
			}
			if (colIsDisplay.equals("是")) {
				cbbTabColumns.setColIsDisplay("Y");
			} else {
				cbbTabColumns.setColIsDisplay("N");
			}
			if (!order.equals("")) {
				cbbTabColumns.setColOrder(new BigDecimal(Integer.parseInt(order)));
				cbbTabColumns.setAttribute11(new BigDecimal(Integer.parseInt(order)));// 表格顺序默认存入表单顺序
			} else {
				String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
				int colOrder = selectMaxOrder(tableId);
				cbbTabColumns.setColOrder(new BigDecimal(colOrder));
				cbbTabColumns.setAttribute11(new BigDecimal(colOrder));// 表格顺序默认存入表单顺序
			}
			if (isMust.equals("是")) {
				cbbTabColumns.setColIsMust("Y");
			} else {
				cbbTabColumns.setColIsMust("N");
			}
			cbbTabColumns.setColIsSys("N");
			cbbTabColumns.setColIsVisible("Y");
			cbbTabColumns.setColIsSearch("N");
			cbbTabColumns.setColIsEdit("Y");
			cbbTabColumns.setColIsTabVisible("N");
			cbbTabColumns.setColIsDetail("Y");
			cbbTabColumns.setColDropdownType("0");
			cbbTabColumns.setColGeneMethod("0");
			cbbTabColumns.setRemark(remark);
			cbbTabColumns.setColShowFormat("0");
			cbbTabColumns.setColIsComplement("N");
			// 调用方法添加
			insertCbbTabColumnsFromExel(cbbTabColumns, sysId, nodeId, nodeName, tableName, orgId, deptId, loginUserId, loginIp, isTrueTable);

		}
	}

	/**
	 * 判断数字格式
	 *
	 * @param length
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	public boolean testMath(String length) {
		// 正则表达式字符串
		String regx = "^[0-9]{1,}$";
		// 定义pattern解释要使用的正则表达式
		Pattern pt = Pattern.compile(regx);
		// 使用Matcher来对比
		Matcher mt = pt.matcher(length);
		// 对比后返回对比结果
		return mt.matches();
	}

	/**
	 * 检测excel数据合法性
	 *
	 * @param datas
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void testExcel(Vector<Vector<String>> datas, String tableId) throws Exception {
		// 数据库表中已存在的字段
		String sql = "select t.COL_NAME from  cbb_tab_columns t where t.TABLE_ID = '" + tableId + "'";
		List<String> existColumns = hibernateDao.findBySQL(sql);
		// 根据表ID查找对应表名
		// String sql2 = "select t.table_name from cbb_tables t where t.id='" +
		// tableId + "'";
		// List<String> tables = hibernateDao.findBySQL(sql2);
		// 对excel文件中的数数据判断（j从1开始，第一行为标题行，直接从数据行开始判断）
		List<String> nameList = new ArrayList<String>();
		for (int j = 1; j < datas.size(); j++) {
			// 一行数据
			try {
				Vector<String> row = datas.get(j);
				String name = row.get(1);// 字段名
				String type = row.get(2);// 字段类型
				String length = row.get(3).replace(".0", "");// 长度
				String decimal = row.get(4).replace(".0", "");// 小数位数
				String colIsSys = row.get(5);// 系统字段
				String colIsDisplay = row.get(6);// 是否可见
				String isMust = row.get(7);// 是否必著
				String order = row.get(8).replace(".0", "");// 字段顺序
				/*** 进行单元格数据格式校验 ***/
				// 字段名校验
				if (!testName(name)) {
					throw new Exception("第" + (j + 1) + "行第2列，【字段名】" + name + "不合法");
				}
				// 字段类型校验，必须是【字符串，整型，日期类型，浮点型】之一
				if (!(type.equals("字符串") || type.equals("整型") || type.equals("日期时间型") || type.equals("浮点型") || type.equals("BLOB") || type.equals("CLOB"))) {
					throw new Exception("第" + (j + 1) + "行第3列，【字段类型】错误");
				}
				// 长度(除日期,BLOB,CLOB类型数据，长度必填)
				if (!type.equals("日期时间型") && !type.equals("BLOB") && !type.equals("CLOB")) {
					if (!testMath(length)) {
						throw new Exception("第" + (j + 1) + "行第4列，【长度】必填且必须是整数");
					}
				}
				// 系统字段
				if (!(colIsSys.equals("是") || colIsSys.equals("否"))) {
					throw new Exception("第" + (j + 1) + "行第6列，【系统字段】必须是【是】或【否】");
				}
				// 是否可见
				if (!(colIsDisplay.equals("是") || colIsDisplay.equals("否"))) {
					throw new Exception("第" + (j + 1) + "行第7列，【是否可见】必须是【是】或【否】");
				}
				// 是否必著
				if (!(isMust.equals("是") || isMust.equals("否"))) {
					throw new Exception("第" + (j + 1) + "行第8列，【是否必著】必须是【是】或【否】");
				}
				// 顺序
				if (!"".equals(order) && !testMath(order)) {
					throw new Exception("第" + (j + 1) + "行第9列，【顺序】必须是整数");
				}
				/*** 进行单元格数据逻辑校验 ***/
				// 判断表中是否已存在
				if (existColumns.contains(name)) {
					throw new Exception("第" + (j + 1) + "行第2列，表中已存在【" + name + "】字段");
				}
				// 判断excel中字段名是否重复
				if (nameList.contains(name)) {
					throw new Exception("第" + (j + 1) + "行第2列，导入数据中，存在相同的字段名【" + name + "】");
				}
				// 类型为字符串时，长度必填，最大4000，小数位数 不能填
				if (type.equals("字符串")) {
					if (Integer.parseInt(length) > 4000) {
						throw new Exception("第" + (j + 1) + "行第4列，字符串的【长度】不能大于4000");
					}
					if (!decimal.equals("")) {
						throw new Exception("第" + (j + 1) + "行第5列，字符串没有【小数位数】");
					}
				}
				// 类型为整型是，长度必填，最大16，小数位数 不能填
				if (type.equals("整型")) {
					if (Integer.parseInt(length) > 16) {
						throw new Exception("第" + (j + 1) + "行第4列，整型的【长度】不能大于16");
					}
					if (!decimal.equals("")) {
						throw new Exception("第" + (j + 1) + "行第5列，整型没有【小数位数】");
					}
				}
				// 类型为浮点数时，长度必填，最大16，小数位数必填，最大6
				if (type.equals("浮点型")) {
					if (Integer.parseInt(length) > 16) {
						throw new Exception("第" + (j + 1) + "行第4列，浮点型的【长度】不能大于16");
					}
					if (!testMath(decimal)) {
						throw new Exception("第" + (j + 1) + "行第5列，浮点型的【小数位数】不能为空且必须是整数");
					}
					if (Integer.parseInt(decimal) > 6) {
						throw new Exception("第" + (j + 1) + "行第5列，浮点型的【小数位数】不能大于6");
					}
				}
				// 日期类型数据的长度不能填，小数位数不能填
				if (type.equals("日期类型")) {
					if (!length.equals("")) {
						throw new Exception("第" + (j + 1) + "行第4列，日期类型的【长度】不能填");
					}
					if (!decimal.equals("")) {
						throw new Exception("第" + (j + 1) + "行第5列，日期类型的【小数位数】不能填");
					}
				}
				// BLOB,CLOB类型数据的长度不能填，小数位数不能填
				if (type.equals("BLOB") || type.equals("CLOB")) {
					if (!length.equals("")) {
						throw new Exception("第" + (j + 1) + "行第4列，日期类型的【长度】不能填");
					}
					if (!decimal.equals("")) {
						throw new Exception("第" + (j + 1) + "行第5列，日期类型的【小数位数】不能填");
					}
				}
				// 将name放入集合中用于检验是否重复
				nameList.add(name);
			} catch (ArrayIndexOutOfBoundsException ae) {
				throw new Exception("导入数据不合法，请在模板中填写数据！");
			} catch (Exception e) {
				throw new Exception("导入数据不合法，请在模板中填写数据！");
			}
		}
	}

	/**
	 * 获取2003文件列值
	 *
	 * @param hssfCell
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	public String getxlsValue(HSSFCell hssfCell) {
		SimpleDateFormat sdf = new SimpleDateFormat(" yyyy-MM-dd ");
		if (hssfCell == null) {
			return "";
		}
		if (hssfCell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
			return String.valueOf(hssfCell.getBooleanCellValue());
		} else if (hssfCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
			if (DateUtil.isCellDateFormatted(hssfCell)) {
				Date date = hssfCell.getDateCellValue();
				return sdf.format(date).trim();
			} else {
				return String.valueOf(hssfCell.getNumericCellValue()).trim();
			}
		} else if (hssfCell.getCellType() == Cell.CELL_TYPE_STRING) {
			return String.valueOf(hssfCell.getStringCellValue()).trim();
		} else if (hssfCell.getCellType() == Cell.CELL_TYPE_BLANK) {
			return "";
		}
		return "";
	}

	/**
	 * 获取文件列类型
	 *
	 * @param hssfCell
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	@SuppressWarnings("static-access")
	public String getxlsCellType(HSSFCell hssfCell) {
		if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
			return "整形";
		} else {
			return "字符串";
		}
	}

	/**
	 * 解析2003excel文件
	 *
	 * @param fileName
	 * @return
	 * @throws IOException
	 *             Map<String,Vector<Vector<String>>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Map<String, Vector<Vector<String>>> readXls(String fileName) throws IOException {
		InputStream is = new FileInputStream(fileName);
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
		Vector<Vector<String>> sheetNames = new Vector<Vector<String>>();
		Vector<String> sheetName = new Vector<String>();
		int columns = 0;
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			Vector<Vector<String>> list = new Vector<Vector<String>>();
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			sheetName.add(hssfSheet.getSheetName());
			for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
				HSSFRow hssfRow = hssfSheet.getRow(rowNum);
				if (hssfRow == null) {
					continue;
				}
				if (rowNum == 0) {
					columns = hssfRow.getLastCellNum();
				}
				Vector<String> title = new Vector<String>();
				Vector<String> row = new Vector<String>();
				for (int cellNum = 0; cellNum < columns; cellNum++) {
					HSSFCell hssfCell = hssfRow.getCell(cellNum);
					if (rowNum == 0) {
						title.add(getxlsValue(hssfCell));
						title.add(getxlsCellType(hssfCell));
					} else {
						row.add(getxlsValue(hssfCell));
					}
				}
				if (rowNum == 0) {
					list.add(title);
				} else {
					list.add(row);
				}
			}
			sheetXls.put(hssfSheet.getSheetName(), list);
		}
		sheetNames.add(sheetName);
		sheetXls.put("sheetNames", sheetNames);
		return sheetXls;
	}

	/**
	 * 获取2007文件列值
	 *
	 * @param xssfCell
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	public String getxlsxValue(XSSFCell xssfCell) {
		SimpleDateFormat sdf = new SimpleDateFormat(" yyyy-MM-dd ");
		if (xssfCell == null) {
			return "";
		}
		if (xssfCell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
			return String.valueOf(xssfCell.getBooleanCellValue());
		} else if (xssfCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
			if (DateUtil.isCellDateFormatted(xssfCell)) {
				Date date = xssfCell.getDateCellValue();
				return sdf.format(date).trim();
			} else {
				return String.valueOf(xssfCell.getNumericCellValue()).trim();
			}
		} else if (xssfCell.getCellType() == Cell.CELL_TYPE_STRING) {
			return String.valueOf(xssfCell.getStringCellValue()).trim();
		} else if (xssfCell.getCellType() == Cell.CELL_TYPE_BLANK) {
			return "";
		}
		return "";
	}

	/**
	 * 解析2007excel文件
	 *
	 * @param fileName
	 * @return
	 * @throws IOException
	 *             Map<String,Vector<Vector<String>>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Map<String, Vector<Vector<String>>> readXlsx(String fileName) throws IOException {
		InputStream is = new FileInputStream(fileName);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
		Vector<Vector<String>> sheetNames = new Vector<Vector<String>>();
		Vector<String> sheetName = new Vector<String>();
		int columns = 0;
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			Vector<Vector<String>> vector2007 = new Vector<Vector<String>>();
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			sheetName.add(xssfSheet.getSheetName());
			// 循环每一行
			for (int rowNum = 0; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
				XSSFRow xssfRow = xssfSheet.getRow(rowNum);
				if (xssfRow == null) {
					continue;
				}
				if (rowNum == 0) { // 列总数
					columns = xssfRow.getLastCellNum();
				}
				Vector<String> title = new Vector<String>();
				Vector<String> row = new Vector<String>();
				// 循环每一列
				for (int cellNum = 0; cellNum < columns; cellNum++) {
					XSSFCell xssfCell = xssfRow.getCell(cellNum);
					if (rowNum == 0) { // 标题行
						// 值
						title.add(getxlsxValue(xssfCell));
						// 类型
						title.add(getxlsxCellType(xssfCell));
					} else { // 数据行
						row.add(getxlsxValue(xssfCell));
					}
				}
				if (rowNum == 0) {
					vector2007.add(title);
				} else {
					vector2007.add(row);
				}
			}
			sheetXlsx.put(xssfSheet.getSheetName(), vector2007.size() > 0 ? vector2007 : new Vector<Vector<String>>());
		}
		sheetNames.add(sheetName);
		sheetXlsx.put("sheetNames", sheetNames);
		return sheetXlsx;
	}

	/**
	 * 获取2007文件列类型
	 *
	 * @param xssfCell
	 * @return String
	 * @throws
	 * @author 朱锋
	 */
	public String getxlsxCellType(XSSFCell xssfCell) {
		if (xssfCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
			return "整形";
		} else {
			return "字符串";
		}
	}

	/**
	 * 判断字段名格式（第一位字母，由字母数字下划线组成）
	 *
	 * @param name
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	public boolean testName(String name) {
		// 正则表达式字符串
		String regx = "^[a-zA-Z][0-9a-zA-Z_]*$";
		// 定义pattern解释要使用的正则表达式
		Pattern pt = Pattern.compile(regx);
		// 使用Matcher来对比
		Matcher mt = pt.matcher(name);
		// 对比后返回对比结果
		return mt.matches();
	}

	/**
	 * 获取基本字段（置为显示的字段）
	 *
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @param isTemplet
	 *            (是否加载全部字段 N：加载基本字段 Y：加载全部字段)
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public List<Map<String, Object>> getCbbTabColumnsJiben(String orgId, String deptId, String sysId, String nodeId, String tableId, String isTemplet) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listFields = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.*\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND T.TABLE_ID = '" + tableId + "'\n");
		if ("N".equals(isTemplet)) {
			sbSql.append("   AND T.COL_IS_DISPLAY = 'Y'\n");
		}
		sbSql.append("   ORDER BY T.COL_ORDER,T.COL_NAME");
		listFields = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listFields;
	}

	/**
	 * 代码维护模块检测excel数据合法性
	 *
	 * @param datas
	 * @param columnId
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void testColCodeExcel(Vector<Vector<String>> datas, String columnId) throws Exception {
		List<String> lookupCodeList = new ArrayList<String>();
		for (int j = 1; j < datas.size(); j++) {
			/*** 一行数据 ***/
			Vector<String> row = datas.get(j);
			String order = row.get(0).replace(".0", "");
			// String lookupName = row.get(1);
			String lookupCode = row.get(2);
			String isValid = row.get(3);
			/*** 调用checkCode（）方法检验是否和表中的数据重复 ***/
			if (checkCode(columnId, lookupCode, "")) {
				throw new Exception("第" + (j + 1) + "行第3列，【真实值】" + lookupCode + " 在数据库中已存在，请查证");
			}
			/*** 检验数据集合中是否存在重复的【真实值】 ***/
			if (lookupCodeList.contains(lookupCode)) {
				throw new Exception("第" + (j + 1) + "行第3列，【真实值】" + lookupCode + " 在文件中已存在，请查证");
			}
			/*** 检验数据格式 ***/
			// 【顺序】必填，正整数
			if (!(testOrder(order) && Integer.parseInt(order) > 0)) {
				throw new Exception("第" + (j + 1) + "行第1列，【顺序】" + order + " 应为正整数，请查证");
			}
			// 【显示值】必填，数字字母下划线组成，最大长度20
			/*
			 * if (!testLookup(lookupName)) { throw new Exception("第" + (j + 1) + "行第2列，【显示值】" + lookupName + "  应由数字，字母，下划线组成且最大长度为20位，请查证"); }
			 */
			// 【真实值】必填，数字字母下划线组成，最大长度20
			/*
			 * if (!testLookup(lookupCode)) { throw new Exception("第" + (j + 1) + "行第3列，【真实值】" + lookupCode + "  应由数字，字母，下划线组成且最大长度为20位，请查证"); }
			 */
			// 【是否有效】必填，必须是有效或无效
			if (!("有效".equals(isValid) || "无效".equals(isValid))) {
				throw new Exception("第" + (j + 1) + "行第4列，【是否有效】" + isValid + " 应为【有效】或【无效】，请查证");
			}
			// 将lookupCode放入集合用重复检验
			lookupCodeList.add(lookupCode);
		}

	}

	/**
	 * 代码维护模块,excel文件【顺序】正则验证
	 *
	 * @param order
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	public boolean testOrder(String order) {
		// 正则表达式字符串
		String regx = "^[0-9]+$";
		// 定义pattern解释要使用的正则表达式
		Pattern pt = Pattern.compile(regx);
		// 使用Matcher来对比
		Matcher mt = pt.matcher(order);
		// 对比后返回对比结果
		return mt.matches();
	}

	/**
	 * 代码维护模块,excel文件【显示值】【真实值】正则验证
	 *
	 * @param lookup
	 * @return boolean
	 * @throws
	 * @author 朱锋
	 */
	public boolean testLookup(String lookup) {
		// 正则表达式字符串
		String regx = "^[0-9a-zA-Z_]{1,20}$";
		// 定义pattern解释要使用的正则表达式
		Pattern pt = Pattern.compile(regx);
		// 使用Matcher来对比
		Matcher mt = pt.matcher(lookup);
		// 对比后返回对比结果
		return mt.matches();
	}

	/**
	 * 代码维护模块,将excel文件中的数据添加到数据库表中
	 *
	 * @param datas
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param columnId
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void inserColCodetFromExcel(Vector<Vector<String>> datas, String orgId, String deptId, String sysId, String columnId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		for (int j = 1; j < datas.size(); j++) {
			/*** 一行数据 ***/
			Vector<String> row = datas.get(j);
			String order = row.get(0).replace(".0", "");
			String lookupName = row.get(1).replace(".0", "");
			String lookupCode = row.get(2).replace(".0", "");
			String isValid = row.get(3);
			/*** 将每一条数据创建成一个CbbTabColCode对象 ***/
			CbbTabColCode cbbTabColCode = new CbbTabColCode();
			BigDecimal bOrder = new BigDecimal(Integer.parseInt(order));
			cbbTabColCode.setCodeOrder(bOrder);
			cbbTabColCode.setColumnId(columnId);
			cbbTabColCode.setLookupName(lookupName);
			cbbTabColCode.setLookupCode(lookupCode);
			if (isValid.equals("有效")) {
				cbbTabColCode.setCodeIsValid("Y");
			}
			if (isValid.equals("无效")) {
				cbbTabColCode.setCodeIsValid("N");
			}
			cbbTabColCode.setTableId(tableId);
			cbbTabColCode.setOrgId(orgId);
			cbbTabColCode.setDeptId(deptId);
			cbbTabColCode.setSysId(sysId);
			/*** 调用方法将CbbTabColCode对象添加到数据库 */
			insertTabColCode(cbbTabColCode);
		}
	}

	/**
	 * 新增或更新列信息后，重新更新列排序号（1.2.3.4....）
	 *
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void updateColOrder(String tableId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("UPDATE CBB_TAB_COLUMNS T\n");
		sbSql.append("   SET T.COL_ORDER =\n");
		sbSql.append("       (SELECT RR\n");
		sbSql.append("          FROM (SELECT TT.ID,\n");
		sbSql.append("                       ROW_NUMBER() OVER(ORDER BY TT.COL_ORDER, TT.COL_NAME) AS RR\n");
		sbSql.append("                  FROM CBB_TAB_COLUMNS TT\n");
		sbSql.append("                 WHERE TT.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("                   AND (TT.COL_IS_SYS = 'N' OR TT.COL_IS_DISPLAY = 'Y')) AA\n");
		sbSql.append("         WHERE AA.ID = T.ID\n");
		sbSql.append("        )\n");
		sbSql.append(" WHERE T.ID IN\n");
		sbSql.append("       (SELECT TT.ID\n");
		sbSql.append("          FROM CBB_TAB_COLUMNS TT\n");
		sbSql.append("         WHERE TT.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("           AND (TT.COL_IS_SYS = 'N' OR TT.COL_IS_DISPLAY = 'Y'))");
		jdbcTemplate.update(sbSql.toString());
	}

	/**
	 * 获取系统操控模版节点ID
	 *
	 * @param sysId
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	public String getInitTemplet(String sysId, String orgId) throws Exception {
		sysId = sysId.toUpperCase();
		String sql = "select t.id from CBB_TEMPLET_INFO t where t.TEMP_TYPE = 'S' and t.sys_id = '" + sysId + "' and t.PARENT_ID ='" + orgId + "'";
		List<Object> list = hibernateDao.findBySQL(sql);
		String templetId = String.valueOf(list.get(0));// templetId
		return templetId;
	}

	/**
	 * 初始化字段同步业务表
	 *
	 * @param sysId
	 * @param orgId
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void sameCbbTabColumnsData(String sysId, String orgId, String deptId, String loginUserId, String loginIp) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql1 = new StringBuffer();
		sbSql1.append("SELECT DISTINCT T.ID, T.TABLE_NAME\n");
		sbSql1.append("  FROM CBB_TABLES T\n");
		sbSql1.append("  LEFT JOIN CBB_TAB_NODE CTN\n");
		sbSql1.append("    ON CTN.TABLE_ID = T.ID\n");
		sbSql1.append(" WHERE T.TABLE_IS_TRUE_TABLE = 'Y'\n");
		sbSql1.append("   AND T.SYS_ID = '" + sysId + "'\n");
		sbSql1.append("   AND (CTN.TAB_FLAG <> '2' OR CTN.TAB_FLAG IS NULL OR CTN.TAB_FLAG = '')");
		List<Object[]> list = hibernateDao.findBySQL(sbSql1.toString());
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = list.get(i);
			String tid = String.valueOf(obj[0]);
			String tableName = String.valueOf(obj[1]);
			// 判断该表是否存在，即判断是否有垃圾数据
			StringBuffer fsbSql = new StringBuffer();
			fsbSql.append("SELECT COUNT(*)\n");
			fsbSql.append("  FROM ALL_TABLES T\n");
			fsbSql.append(" WHERE T.TABLE_NAME = '" + tableName + "'\n");
			List<Object> flist = hibernateDao.findBySQL(fsbSql.toString());
			String flagNum = String.valueOf(flist.get(0));
			if (!"0".equals(flagNum)) {
				StringBuffer sbSql = new StringBuffer();
				sbSql.append("SELECT CTF.*\n");
				sbSql.append("  FROM CBB_TEMPLET_INFO CTI\n");
				sbSql.append("  LEFT JOIN CBB_TEMPLET_FIELD CTF\n");
				sbSql.append("    ON CTI.ID = CTF.TEMPLET_ID\n");
				sbSql.append(" WHERE CTI.SYS_ID = '" + sysId + "'\n");
				sbSql.append("   AND CTI.TEMP_TYPE = 'S'\n");
				sbSql.append("   AND CTF.COL_NAME NOT IN\n");
				sbSql.append("       (SELECT CTC.COL_NAME\n");
				sbSql.append("          FROM CBB_TAB_COLUMNS CTC\n");
				sbSql.append("         WHERE CTC.TABLE_ID = '" + tid + "')");
				List<Map<String, Object>> listColnums = jdbcAvicit.queryForMap(sbSql.toString(), null);
				// 循环所有列信息
				for (int j = 0; j < listColnums.size(); j++) {
					Map<String, Object> map = listColnums.get(j);
					// 新增列属性
					CbbTabColumns cbbTabColumns = new CbbTabColumns();
					String cid = ComUtil.getId();
					cbbTabColumns.setId(cid);
					cbbTabColumns.setTableId(tid);
					cbbTabColumns.setColName(String.valueOf(map.get("COL_NAME")));
					cbbTabColumns.setColLabel(String.valueOf(map.get("COL_LABEL")));
					cbbTabColumns.setColType(String.valueOf(map.get("COL_TYPE")));
					/*** 2015/11/16 - 更改 （郭亮）对‘字段长度’进行非空判断 ***/
					Object colLen = map.get("COL_LENGTH");
					BigDecimal colLength = null;
					if (null != colLen) {
						BigDecimal colLenB = new BigDecimal(Integer.parseInt(String.valueOf(colLen)));
						colLength = colLenB;
						cbbTabColumns.setColLength(colLenB);
					}
					/*** 2015/11/16 - 更改 （郭亮） ***/
					Object colDecimal = map.get("COL_DECIMAL");
					if (null != map.get("COL_DECIMAL")) {
						BigDecimal colDecimaln = new BigDecimal(Integer.parseInt(String.valueOf(map.get("COL_DECIMAL"))));
						cbbTabColumns.setColDecimal(colDecimaln);
					}
					cbbTabColumns.setColIsSys("Y");
					int colOrder = selectMaxOrder(tid);
					cbbTabColumns.setColOrder(new BigDecimal(colOrder));
					int colTabOrder = selectMaxTabOrder(tid);
					cbbTabColumns.setAttribute11(new BigDecimal(colTabOrder));
					cbbTabColumns.setColIsMust(String.valueOf(map.get("COL_IS_MUST")));
					cbbTabColumns.setColIsVisible("Y");
					cbbTabColumns.setColIsSearch("N");
					cbbTabColumns.setColIsEdit("Y");
					cbbTabColumns.setColIsTabVisible("N");
					cbbTabColumns.setColIsDetail("Y");
					cbbTabColumns.setColDropdownType(String.valueOf(map.get("COL_DROPDOWN_TYPE")));
					cbbTabColumns.setColGeneMethod("0");
					cbbTabColumns.setColRuleName(String.valueOf(map.get("COL_RULE_NAME")));
					cbbTabColumns.setColRuleTitle(String.valueOf(map.get("COL_RULE_TITLE")));
					cbbTabColumns.setCustomPath(String.valueOf(map.get("CUSTOM_PATH")));
					String colRemark = String.valueOf(map.get("REMARK"));
					if (null == colRemark || "null".equals(colRemark)) {
						colRemark = "";
					}
					cbbTabColumns.setRemark(colRemark);
					cbbTabColumns.setSysId(sysId);
					cbbTabColumns.setOrgId(orgId);
					cbbTabColumns.setDeptId(deptId);
					cbbTabColumns.setCreatedBy(loginUserId);
					cbbTabColumns.setLastUpdatedBy(loginUserId);
					cbbTabColumns.setLastUpdateIp(loginIp);
					cbbTabColumns.setColIsDisplay(String.valueOf(map.get("COL_IS_DISPLAY")));
					cbbTabColumns.setColShowFormat("0");
					cbbTabColumns.setColIsComplement("N");
					insertCbbTabColumus(cbbTabColumns);
					// 添加该列的通用代码
					// 自建的通用代码
					String sqlZj = "SELECT T.* FROM CBB_TEMPLET_CODE T WHERE T.FIELD_ID = '" + String.valueOf(map.get("ID")) + "'";
					List<Map<String, Object>> listCodeZj = jdbcAvicit.queryForMap(sqlZj, null);
					for (int k = 0; k < listCodeZj.size(); k++) {
						Map<String, Object> mapZj = listCodeZj.get(k);
						CbbTabColCode cbbTabColCode = new CbbTabColCode();
						cbbTabColCode.setTableId(tid);
						cbbTabColCode.setColumnId(cid);
						BigDecimal bdco = new BigDecimal(String.valueOf(mapZj.get("CODE_ORDER")));
						cbbTabColCode.setCodeOrder(bdco);
						cbbTabColCode.setLookupName(String.valueOf(mapZj.get("LOOKUP_NAME")));
						cbbTabColCode.setLookupCode(String.valueOf(mapZj.get("LOOKUP_CODE")));
						cbbTabColCode.setCodeIsValid(String.valueOf(mapZj.get("CODE_IS_VALID")));
						String colCodeRemark = String.valueOf(String.valueOf(mapZj.get("REMARK")));
						if (null == colCodeRemark || "null".equals(colRemark)) {
							colCodeRemark = "";
						}
						cbbTabColCode.setRemark(colCodeRemark);
						cbbTabColCode.setSysId(sysId);
						cbbTabColCode.setOrgId(orgId);
						cbbTabColCode.setDeptId(deptId);
						insertTabColCode(cbbTabColCode);
					}

					// 系统的通用代码
					String sqlXt = "SELECT T.* FROM CBB_TEMPLET_SYS_CODE T WHERE T.FIELD_ID = '" + String.valueOf(map.get("ID")) + "'";
					List<Map<String, Object>> listCodeXt = jdbcAvicit.queryForMap(sqlXt, null);
					for (int k = 0; k < listCodeXt.size(); k++) {
						Map<String, Object> mapXt = listCodeXt.get(k);
						CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
						cbbTabColSysCode.setTableId(tid);
						cbbTabColSysCode.setColumnId(cid);
						cbbTabColSysCode.setSysLookupId(String.valueOf(mapXt.get("SYS_LOOKUP_ID")));
						String colCodeRemark = String.valueOf(mapXt.get("REMARK"));
						if (null == colCodeRemark || "null".equals(colRemark)) {
							colCodeRemark = "";
						}
						cbbTabColSysCode.setRemark(colCodeRemark);
						cbbTabColSysCode.setSysId(sysId);
						cbbTabColSysCode.setOrgId(orgId);
						cbbTabColSysCode.setDeptId(deptId);
						insertTabColSysCode(cbbTabColSysCode);
					}
					// 判断实体表中是否存在该字段
					StringBuffer fcolSql = new StringBuffer();
					fcolSql.append("SELECT COUNT(*)\n");
					fcolSql.append("  FROM ALL_COL_COMMENTS T\n");
					fcolSql.append(" WHERE T.TABLE_NAME = '" + tableName + "'\n");
					fcolSql.append("   AND T.COLUMN_NAME = '" + cbbTabColumns.getColName().toUpperCase() + "'");
					List<Object> fcollist = hibernateDao.findBySQL(fcolSql.toString());
					String flagColNum = String.valueOf(fcollist.get(0));
					if ("0".equals(flagColNum)) {
						// 操作真实表结构
						// 查询SYSID及组织ID，获取所对应的用户名
						List<Map<String, Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId, "");
						String dbUser = "";// 用户名
						if (listConn.size() > 0) {
							Map<String, Object> connmap = listConn.get(0);
							dbUser = String.valueOf(connmap.get("DB_USER"));
						} else {
							throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
						}
						// 给实体表新增字段
						String colType = cbbTabColumns.getColType();
						// 判断列类型
						if (colType.equals("string")) {
							colType = "VARCHAR2(" + (null == colLength ? "128" : colLength) + ")";
						} else if (colType.equals("integer")) {
							colType = "NUMBER" + "(" + (null == colLength ? "16" : colLength) + ")";
						} else if (colType.equals("date")) {
							colType = "DATE";
						} else if (colType.equals("float")) {
							colType = "NUMBER" + "(" + (null == colLength ? "16" : colLength) + "," + (null == colDecimal ? "6" : String.valueOf(colDecimal)) + ")";
						} else if (colType.equals("blob")) {
							colType = "BLOB";
						} else if (colType.equals("clob")) {
							colType = "CLOB";
						}
						try {
							String addCol = "ALTER TABLE " + dbUser + "." + tableName + " ADD " + cbbTabColumns.getColName() + " " + colType;
							this.jdbcAvicit.getJdbcTemplate().execute(addCol);
							this.jdbcAvicit.getJdbcTemplate().execute("commit");
							SysLogUtil.log("库结构定义模块", "新增列(实体表)记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
							// 给此字段增加注释
							addCol = "COMMENT ON COLUMN " + tableName + "." + cbbTabColumns.getColName() + "\n" + "  is '" + cbbTabColumns.getColLabel() + "'";
							this.jdbcAvicit.getJdbcTemplate().execute(addCol);
							this.jdbcAvicit.getJdbcTemplate().execute("commit");
							SysLogUtil.log("库结构定义模块", "新增列(实体表)记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
						} catch (Exception e) {
							e.printStackTrace();
							// 回滚添加列的数据
							CbbTabColumns cbbTabColumnsTemp = new CbbTabColumns();
							cbbTabColumnsTemp = getCbbTabColumnsById(cid);
							deleteCbbTabColumnsById(cbbTabColumnsTemp);
							String mes = "数据库操作异常，请联系管理员！";
							throw new Exception(mes);
						}
					}
					// 给表单配置信息表添加数据
					List<String> formIdList = getFormIdByTableIdByFormConfig(sysId, tid);// formId
					String formId = "";
					if (formIdList.size() > 0) {
						formId = formIdList.get(0);
					}
					if (!"".equals(formId)) {
						// 根据formId和columnId判断该字段是否已经存在配置信息
						boolean hasConfig = billDefineManagerService.getformConfigByFormIdAndColId(formId, cid);
						if (!hasConfig) {
							String formConfigId = ComUtil.getId();
							CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
							cbbTabFormConfig.setId(formConfigId);
							cbbTabFormConfig.setFormId(formId);
							cbbTabFormConfig.setColumnId(cid);
							BigDecimal formVertical = new BigDecimal(1);
							cbbTabFormConfig.setFormVertical(formVertical);
							BigDecimal formHorizontal = new BigDecimal(1);
							cbbTabFormConfig.setFormHorizontal(formHorizontal);
							cbbTabFormConfig.setOrgId(orgId);
							cbbTabFormConfig.setDeptId(deptId);
							cbbTabFormConfig.setSysId(sysId);
							cbbTabFormConfig.setAttribute11(cbbTabColumns.getColOrder());
							PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
							hibernateDao.save(cbbTabFormConfig);
							SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
						}
					}
					// 同步节点著录定义配置信息
					// Map<String, Object> tabNodeRecordParam = new
					// HashMap<String, Object>();
					// tabNodeRecordParam.put("sysId", sysId);
					// tabNodeRecordParam.put("orgId", orgId);
					// tabNodeRecordParam.put("deptId", deptId);
					// tabNodeRecordParam.put("tableId", tid);
					// tabNodeRecordParam.put("obj", cbbTabColumns);
					// this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
				}
			}
		}
	}

	/**
	 * 根据tableId查找表是否为真实表
	 *
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public String findTableisTureTable(String tableId) throws Exception {
		String sql = "SELECT T.TABLE_IS_TRUE_TABLE FROM CBB_TABLES T WHERE T.ID='" + tableId + "'";
		List<String> list = hibernateDao.findBySQL(sql);
		if (null != list && list.size() > 0) {
			return list.get(0);
		} else {
			return null;
		}
	}

	/**
	 * 根据字段ID查找字段设置的通用代码
	 */
	@Override
	public List<Object[]> getLookupCodeByColumnId(String columnId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTCC.LOOKUP_NAME, CTCC.LOOKUP_CODE\n");
		sbSql.append("  FROM CBB_TAB_COL_CODE CTCC\n");
		sbSql.append(" WHERE CTCC.COLUMN_ID = '" + columnId + "'\n");
		sbSql.append("UNION\n");
		sbSql.append("SELECT CLV.LOOKUP_NAME, CLV.LOOKUP_CODE\n");
		sbSql.append("  FROM CBB_TAB_COL_SYS_CODE CTCSC\n");
		sbSql.append("  LEFT JOIN CBB_LOOKUP_V CLV\n");
		sbSql.append("    ON CLV.ID = CTCSC.SYS_LOOKUP_ID\n");
		sbSql.append(" WHERE CTCSC.COLUMN_ID = '" + columnId + "'");
		List<Object[]> colCodeList = hibernateDao.findBySQL(sbSql.toString());
		return colCodeList;
	}

	/***
	 * 根据userId查找userName
	 *
	 * @return
	 */
	@Override
	public String getUserNameById(String id) throws Exception {
		String names = "";
		if (!"".equals(id) && id != null) {
			String[] ids = id.split(",");
			for (int i = 0; i < ids.length; i++) {
				String sql = "SELECT T.NAME FROM SYS_USER T WHERE T.ID = '" + ids[i] + "'";
				List<String> nameList = this.hibernateDao.findBySQL(sql);
				if (nameList != null && nameList.size() > 0) {
					names = names + "," + nameList.get(0);
				}
			}
			if (!"".equals(names)) {
				names = names.substring(1, names.length());
			}
		}
		return names;
	}

	/***
	 * 根据deptId查找deptName
	 *
	 * @return
	 */
	@Override
	public String getDeptNameById(String id) throws Exception {
		String names = "";
		if (!"".equals(id) && id != null) {
			String[] ids = id.split(",");
			for (int i = 0; i < ids.length; i++) {
				String sql = "SELECT T.DEPT_NAME FROM SYS_DEPT_V T WHERE T.ID = '" + ids[i] + "'";
				List<String> nameList = this.hibernateDao.findBySQL(sql);
				if (nameList != null && nameList.size() > 0) {
					names = names + "," + nameList.get(0);
				}
			}
			if (!"".equals(names)) {
				names = names.substring(1, names.length());
			}
		}
		return names;
	}

	/***
	 * 根据sysCode查找sysName
	 *
	 * @return
	 */
	@Override
	public String getSysNameByCode(String code) throws Exception {
		String sqlCustom = "SELECT T.SYS_NAME FROM CBB_SYS_INFO T WHERE T.ID = '" + code + "'";
		List<String> sysNameList = this.hibernateDao.findBySQL(sqlCustom);
		if (sysNameList != null && sysNameList.size() > 0) {
			return sysNameList.get(0);
		}
		return "";
	}

	/**
	 * 参考模板复制字段信息加载库结构树
	 *
	 * @param id
	 * @param copyNodeData
	 * @return
	 * @throws Exception
	 *             List<TreeNode>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public List<TreeNode> recurFindTreeNodesByParentIdInCommTemplet(String id, String copyNodeData, String sysId, String orgId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		// 查询业务数据
		List<Map<String, Object>> childTreeList = findCopyNodesByParentId(id, copyNodeData, sysId, orgId);
		// 将业务数据格式转换成esayui树形格式
		for (Map<String, Object> row : childTreeList) {
			String rid = (String) row.get("ID");
			String rname = (String) row.get("NODE_NAME");
			String icon = (String) row.get("ICON");// 图片名称
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			node.setIconCls(icon);
			node.setAttributes(row);
			node.set_parentId((String) row.get("PARENT_ID"));
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = recurFindTreeNodesByParentIdInCommTemplet(rid, copyNodeData, sysId, orgId);
				node.getChildren().addAll(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodes.add(node);
		}
		return nodes;
	}

	/**
	 * 获取子节点
	 *
	 * @param parentId
	 * @param copyNodeData
	 * @return List<Map < String, Object>>
	 * @throws
	 * @author 朱锋
	 */
	public List<Map<String, Object>> findCopyNodesByParentId(String parentId, String copyNodeData, String sysId, String orgId) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		if ("IETD".equals(sysId)) {
			if ("ROOT".equals(parentId)) {
				parentId = "root";
			}
		}
		Assert.notNull(parentId, "参数不能为空！");
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT T.*,\n");
		sb.append("       (SELECT COUNT(*)\n");
		sb.append("          FROM " + copyNodeData + " F\n");
		sb.append("         WHERE F.PARENT_ID = '" + parentId + "'" + " \n");
		sb.append("        ) CHILD_COUNT\n");
		sb.append("  FROM " + copyNodeData + " T\n");
		sb.append(" WHERE T.PARENT_ID = '" + parentId + "' AND T.ORG_ID = '" + orgId + "'\n");
		sb.append("CONNECT BY PRIOR T.ID = T.PARENT_ID\n");
		sb.append(" START WITH T.PARENT_ID = '" + parentId + "'");
		sb.append(" ORDER BY T.NODE_SORT_NUMBER ASC,T.CREATION_DATE ASC");
		return this.jdbcTemplate.queryForList(sb.toString());
	}

	/**
	 * 获取索引主界面表格数据
	 *
	 * @param page
	 * @param parameter
	 * @param sysId
	 * @return
	 * @throws Exception
	 *             Map<String,Object>
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public Map<String, Object> getIndexPageDetailList(Paging<CbbTabColumns> page, Map<String, Object> parameter, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tableId = String.valueOf(parameter.get("tableId"));
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTCI.ID, CTCI.INDEX_TYPE, CTCI.INDEX_NAME, CTCI.COLUMN_ID AS COL_ID\n");
		sbSql.append("  FROM CBB_TAB_COL_INDEX CTCI\n");
		sbSql.append("  WHERE CTCI.TABLE_ID = '" + tableId + "'\n");
		String sql = sbSql.toString();
		String sqlCount = "select count(1) from (" + sql + ")";
		List<Object> sqlCountList = hibernateDao.findBySQL(sqlCount);
		String count = String.valueOf(sqlCountList.get(0));
		int firstResult = page.getPageNo();
		int maxResults = page.getPageSize();
		if (firstResult <= 1) {
			sql = "select * from ( " + sql + " ) where rownum <= " + maxResults;
		} else {
			sql = "select * from ( select row_.*, rownum rownum_var from ( " + sql + " ) row_ where rownum <= " + (firstResult * maxResults) + ") where rownum_var > " + (firstResult - 1) * maxResults;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> list = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 构造COL_LABEL,COL_NAME
		for (int i = 0; i < list.size(); i++) {
			// id串
			String ids = String.valueOf(list.get(i).get("COL_ID"));
			String[] idArr = ids.split(",");
			// 根据ID查找字段名和字段中文名
			String colName = "";
			String colLable = "";
			if (idArr.length == 1) { // 单个字段
				String nameSql = "SELECT T.COL_NAME,T.COL_LABEL FROM CBB_TAB_COLUMNS T WHERE T.COL_IS_DISPLAY = 'Y' AND T.ID = '" + ids + "'";
				List<Object[]> nameList = this.hibernateDao.findBySQL(nameSql);
				if (nameList.size() > 0) {
					colName = String.valueOf(nameList.get(0)[0]);
					colLable = String.valueOf(nameList.get(0)[1]);
				}

			} else {
				for (int j = 0; j < idArr.length; j++) {
					String nameSql2 = "SELECT T.COL_NAME,T.COL_LABEL FROM CBB_TAB_COLUMNS T WHERE T.COL_IS_DISPLAY = 'Y' AND T.ID = '" + idArr[j] + "'";
					List<Object[]> nameList2 = this.hibernateDao.findBySQL(nameSql2);
					if (nameList2.size() > 0) {
						colName = colName + "," + String.valueOf(nameList2.get(0)[0]);
						colLable = colLable + "," + String.valueOf(nameList2.get(0)[1]);
					}
				}
				colName = colName.substring(1, colName.length());
				colLable = colLable.substring(1, colLable.length());
			}
			// 想map中填充colName和colLabel
			list.get(i).put("COL_NAME", colName);
			list.get(i).put("COL_LABEL", colLable);
		}
		map.put("count", count);
		map.put("list", list);
		return map;
	}

	/**
	 * 索引主页面数据删除方法
	 *
	 * @param deleteData
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @param isTrueTable
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void deleteCbbTabIndexDataById(String deleteData, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		if (!"".equals(deleteData) && !"[]".equals(deleteData)) {
			// 连接池
			DBConnectionCustomManager connectionMan = null;
			String poolName = orgId + "_" + sysId;
			Connection conn = null;
			Statement statement = null;
			try {
				// 实例化连接池
				connectionMan = DBConnectionCustomManager.getInstance(poolName);
				// 获取连接
				conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
				statement = conn.createStatement();
				String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);// 获取表ID
				CbbTables cbbTables = getCbbTablesById(tableId);// 获取表对象
				JSONArray ja = JSONArray.fromObject(deleteData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");// 索引主键ID
					if (!"".equals(id)) {
						String indexName = jj.getString("INDEX_NAME");// 索引名称
						String indexType = jj.getString("INDEX_TYPE");// 索引类型（1
						// 普通索引
						// 2
						// 唯一索引）
						if (!"".equals(id) && !"null".equals(id)) {
							// 虚拟表及类型为【唯一索引】的不进行实体表维护
							if (!"N".equals(cbbTables.getTableIsTrueTable()) && !"2".equals(indexType)) {
								// 删除ORACLE一般索引
								String sql = "DROP INDEX " + indexName;
								statement.execute(sql);
								SysLogUtil.log("库结构定义模块", "删除列索引记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
							}
							CbbTabColIndex cbbTabColIndex = getCbbTabColIndexById(id);
							deleteCbbTabColIndex(cbbTabColIndex);
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (statement != null) {
					try {
						statement.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				if (conn != null) {
					try {
						connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	/**
	 * 索引主页面数据新增方法
	 *
	 * @param cbbTabColumnsArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @param orgId
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 * @param isTrueTable
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void insertCbbTabIndex(String insertData, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId, String loginUserId, String loginIp) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		if (!"".equals(insertData) && !"[]".equals(insertData)) {
			// 连接池
			DBConnectionCustomManager connectionMan = null;
			String poolName = orgId + "_" + sysId;
			Connection conn = null;
			Statement statement = null;
			try {
				// 实例化连接池
				connectionMan = DBConnectionCustomManager.getInstance(poolName);
				// 获取连接
				conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
				statement = conn.createStatement();
				String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);// 获取表ID
				CbbTables cbbTables = getCbbTablesById(tableId);// 获取表对象
				JSONArray ja = JSONArray.fromObject(insertData);
				for (int i = 0; i < ja.size(); i++) {
					CbbTabColIndex cbbTabColIndex = new CbbTabColIndex();
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String columnId = jj.getString("COL_ID");// 列ID
					String indexName = jj.getString("INDEX_NAME");// 索引名称
					String colName = jj.getString("COL_NAME");// 列英文名
					String indexType = jj.getString("INDEX_TYPE");// 索引类型（1 普通索引
					// 2 唯一索引）
					// 根据indexType进行唯一性校验
					if ("1".equals(indexType)) {
						// 判断该字段是否已经存在 普通索引
						if (ckeckCommnIndexUnique(columnId, indexType)) {
							// 添加index类
							String id = ComUtil.getId();// 自动生成的主键ID
							cbbTabColIndex.setId(id);
							cbbTabColIndex.setIndexName(indexName);
							cbbTabColIndex.setTableId(tableId);
							cbbTabColIndex.setColumnId(columnId);
							cbbTabColIndex.setOrgId(orgId);
							cbbTabColIndex.setDeptId(deptId);
							cbbTabColIndex.setSysId(sysId);
							cbbTabColIndex.setIndexType(indexType);
							PojoUtil.setSysProperties(cbbTabColIndex, OpType.insert);
							hibernateDao.save(cbbTabColIndex);
							SysLogUtil.log(cbbTabColIndex, null, OpType.insert, OpResult.success);
							// 虚拟表及类型为【唯一索引】的不进行实体表维护
							if (!"N".equals(cbbTables.getTableIsTrueTable())) {
								// 给此字段增加注释
								String sql = "CREATE INDEX " + indexName + " ON " + tableName + " (" + colName + ")";
								statement.execute(sql);
								SysLogUtil.log("库结构定义模块", "创建列索引记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
							}
						} else {
							throw new Exception("不能给同一字段添加同一类型的索引，请查证！");
						}
					} else {
						// ID排序
						String[] colIdArr = columnId.split(",");
						Arrays.sort(colIdArr);
						// 将排序后的字符串数组准换成字符串
						String columnIdSorted = "";
						for (int j = 0; j < colIdArr.length; j++) {
							columnIdSorted = columnIdSorted + "," + colIdArr[j];
						}
						columnIdSorted = columnIdSorted.substring(1, columnIdSorted.length());
						// 判断该字段是否已经存在唯一索引
						if (ckeckCommnIndexUnique(columnIdSorted, indexType)) {
							// 添加index类
							String id = ComUtil.getId();// 自动生成的主键ID
							cbbTabColIndex.setId(id);
							cbbTabColIndex.setIndexName(indexName);
							cbbTabColIndex.setTableId(tableId);
							cbbTabColIndex.setColumnId(columnIdSorted);
							cbbTabColIndex.setOrgId(orgId);
							cbbTabColIndex.setDeptId(deptId);
							cbbTabColIndex.setSysId(sysId);
							cbbTabColIndex.setIndexType(indexType);
							PojoUtil.setSysProperties(cbbTabColIndex, OpType.insert);
							hibernateDao.save(cbbTabColIndex);
							SysLogUtil.log(cbbTabColIndex, null, OpType.insert, OpResult.success);
						} else {
							throw new Exception("不能给同一字段添加同一类型的索引，请查证！");
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (statement != null) {
					try {
						statement.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				if (conn != null) {
					try {
						connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	/***
	 * 索引主页面数据更新方法
	 *
	 * @author 郭亮
	 * @param updatetData
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @param orgId
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void updateCbbTabIndex(String updatetData, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId, String loginUserId, String loginIp) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		if (!"".equals(updatetData) && !"[]".equals(updatetData)) {
			// 连接池
			DBConnectionCustomManager connectionMan = null;
			String poolName = orgId + "_" + sysId;
			Connection conn = null;
			Statement statement = null;
			try {
				// 实例化连接池
				connectionMan = DBConnectionCustomManager.getInstance(poolName);
				// 获取连接
				conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
				statement = conn.createStatement();
				String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);// 获取表ID
				CbbTables cbbTables = getCbbTablesById(tableId);// 获取表对象
				JSONArray ja = JSONArray.fromObject(updatetData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					String columnId = jj.getString("COL_ID");// 列ID
					String indexName = jj.getString("INDEX_NAME");// 索引名称
					String colName = jj.getString("COL_NAME");// 列英文名
					String indexType = jj.getString("INDEX_TYPE");// 索引类型（1 普通索引
					// 2 唯一索引）
					String oldIndexType = this.getCbbTabColIndexById(id).getIndexType();
					if ("1".equals(indexType)) {
						// 库表操作,更新数据
						CbbTabColIndex oldBean = this.getCbbTabColIndexById(id);
						hibernateDao.evict(oldBean);
						CbbTabColIndex newBean = new CbbTabColIndex();
						PojoUtil.copyProperties(newBean, oldBean, true);
						newBean.setColumnId(columnId);
						newBean.setIndexName(indexName);
						newBean.setIndexType(indexType);
						SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
						PojoUtil.setSysProperties(newBean, OpType.update);
						hibernateDao.update(newBean);
						// oracle操作
						if ("1".equals(oldIndexType)) {
							// 删除索引
							if (!"N".equals(cbbTables.getTableIsTrueTable())) { // 虚拟表及类型为【唯一索引】的不进行实体表维护
								// 给此字段增加注释
								String sql = "drop index " + indexName;
								statement.execute(sql);
								SysLogUtil.log("库结构定义模块", "删除列索引记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
							}
						}
						// 新增索引
						if (!"N".equals(cbbTables.getTableIsTrueTable())) {
							// 给此字段增加注释
							String sql = "CREATE INDEX " + indexName + " ON " + tableName + " (" + colName + ")";
							statement.execute(sql);
							SysLogUtil.log("库结构定义模块", "创建列索引记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
						}
					} else {
						// ID排序
						String[] colIdArr = columnId.split(",");
						Arrays.sort(colIdArr);
						// 将排序后的字符串数组准换成字符串
						String columnIdSorted = "";
						for (int j = 0; j < colIdArr.length; j++) {
							columnIdSorted = columnIdSorted + "," + colIdArr[j];
						}
						// 库表操作,更新数据
						columnIdSorted = columnIdSorted.substring(1, columnIdSorted.length());
						CbbTabColIndex oldBean = this.getCbbTabColIndexById(id);
						hibernateDao.evict(oldBean);
						CbbTabColIndex newBean = new CbbTabColIndex();
						PojoUtil.copyProperties(newBean, oldBean, true);
						newBean.setColumnId(columnIdSorted);
						newBean.setIndexName(indexName);
						newBean.setIndexType(indexType);
						SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
						PojoUtil.setSysProperties(newBean, OpType.update);
						hibernateDao.update(newBean);
						// oracle操作
						if ("1".equals(oldIndexType)) {
							// 删除索引
							if (!"N".equals(cbbTables.getTableIsTrueTable())) { // 虚拟表及类型为【唯一索引】的不进行实体表维护
								// 给此字段增加注释
								String sql = "drop index " + indexName;
								statement.execute(sql);
								SysLogUtil.log("库结构定义模块", "删除列索引记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
							}
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (statement != null) {
					try {
						statement.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				if (conn != null) {
					try {
						connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	/**
	 * 删除索引信息
	 *
	 * @param cbbTabColIndex
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	public void deleteCbbTabColIndex(CbbTabColIndex cbbTabColIndex) throws Exception {
		try {
			// 删除基本字段信息
			hibernateDao.delete(cbbTabColIndex);
			SysLogUtil.log(cbbTabColIndex, null, OpType.delete, OpResult.success);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据表ID获取设置为可见的字段集合(供索引应用)
	 *
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public List<Object[]> getCbbTabColsByTableId(String tableId) throws Exception {
		List<Object[]> list = new ArrayList<Object[]>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID, T.COL_LABEL\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.COL_TYPE NOT IN ('clob','blob')\n");
		sbSql.append("   AND T.COL_IS_DISPLAY = 'Y'\n");
		sbSql.append("   AND T.TABLE_ID = '" + tableId + "'");
		list = hibernateDao.findBySQL(sbSql.toString());
		return list;
	}

	/**
	 * 判断该字段是否已经存在唯一索引
	 *
	 * @param colId
	 * @return
	 * @throws Exception
	 *             boolean
	 * @throws
	 * @author 朱锋
	 */
	public boolean checkCbbIndexTypeByColId(String colId) throws Exception {
		boolean flag = false;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*)\n");
		sbSql.append("  FROM CBB_TAB_COL_INDEX T\n");
		sbSql.append(" WHERE T.INDEX_TYPE = '2'\n");
		sbSql.append("   AND T.COLUMN_ID = '" + colId + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		int num = 0;
		if (list.size() > 0) {
			num = Integer.parseInt(String.valueOf(list.get(0)));
		}
		if (num > 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 获取顺带字段
	 *
	 * @param tableId
	 * @param colType
	 * @param colId
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 * @throws
	 */
	@Override
	public String getColNmaeByColTypeIncidentally(String tableId, String colType, String colId, String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 文件级非ARCHIVE_CODE字段可以组合案卷级和文件级字段，案卷级字段只能组合案卷级字段
		// 判断表类型(文件级，案卷级)
		boolean ajjFlag = checkTabIsAJJ(tableId, nodeId);// 案卷级表标识
		getColumnNameById(colId);
		String colNmeStr = "";
		if (!ajjFlag) { // 文件级表字段
			// 根据nodeId查找tableId
			List<Map<String, Object>> tabIdList = this.getCbbTableIdsByNodeIdByIntfs(orgId, deptId, sysId, nodeId);
			if (tabIdList.size() > 0) {
				colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
				for (int i = 0; i < tabIdList.size(); i++) {
					Map<String, Object> tabIdMap = tabIdList.get(i);
					String tabId = (String) tabIdMap.get("TABLE_ID");
					String tabTitle = this.getTabTitleByTabId(tabId);
					// 根据tableId查找可组合字段
					StringBuffer sql = new StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tabId + "' AND T.COL_IS_DISPLAY='Y'");
					if (tableId.equals(tabId)) {
						// sql.append(" AND T.ID <> '" + colId + "'");
					}
					if ("integer".equals(colType)) { // 整型
						sql.append(" AND T.COL_TYPE = 'integer'");
					} else if ("float".equals(colType)) {
						sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
					} else if ("date".equals(colType)) {
						sql.append(" AND T.COL_TYPE = 'date'");
					}
					List<Object[]> titleList = this.hibernateDao.findBySQL(sql.toString());
					if (titleList.size() > 0) {
						for (int j = 0; j < titleList.size(); j++) {
							// 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
							String lookupName = tabTitle + "." + (String) titleList.get(j)[0];
							String lookupCode = tabId + "," + (String) titleList.get(j)[1];
							colNmeStr = colNmeStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
						}
					}
				}
				colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
				colNmeStr = colNmeStr + "]";
			}
		} else { // 案卷级表字段
			colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
			// 根据tableId查找可组合字段
			String tabTitle = this.getTabTitleByTabId(tableId);
			StringBuffer sql = new StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tableId + "' AND T.COL_IS_DISPLAY='Y'");
			if (tableId.equals(tableId)) {
				// sql.append(" AND T.ID <> '" + colId + "'");
			}
			if ("integer".equals(colType)) { // 整型
				sql.append(" AND T.COL_TYPE = 'integer'");
			} else if ("float".equals(colType)) {
				sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
			} else if ("date".equals(colType)) {
				sql.append(" AND T.COL_TYPE = 'date'");
			}
			List<Object[]> titleList = this.hibernateDao.findBySQL(sql.toString());
			if (titleList.size() > 0) {
				for (int j = 0; j < titleList.size(); j++) {
					// 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
					String lookupName = tabTitle + "." + (String) titleList.get(j)[0];
					String lookupCode = tableId + "," + (String) titleList.get(j)[1];
					colNmeStr = colNmeStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
				}
			}
			colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
			colNmeStr = colNmeStr + "]";
		}
		return colNmeStr;
	}

	/***
	 * 配置组合项时，构造可组合字段下拉列表(lookupName:表名.字段名,lookupCode:tableId.columnId)
	 */
	@Override
	public String getColNmaeByColType(String tableId, String colType, String colId, String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 文件级非ARCHIVE_CODE字段可以组合案卷级和文件级字段，案卷级字段只能组合案卷级字段
		// 判断表类型(文件级，案卷级)
		boolean ajjFlag = checkTabIsAJJ(tableId, nodeId);// 案卷级表标识
		getColumnNameById(colId);
		String colNmeStr = "";
		if (!ajjFlag) { // 文件级表字段
			// if ("ARCHIVE_CODE".equals(colName)) { //
			// 文件级表中的ARCHIVE_CODE字段，只能组合文件级字段
			// colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
			// // 根据tableId查找可组合字段
			// String tabTitle = this.getTabTitleByTabId(tableId);
			// StringBuffer sql = new
			// StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '"
			// + tableId + "' AND T.COL_IS_DISPLAY='Y'");
			// if (tableId.equals(tableId)) {
			// sql.append(" AND T.ID <> '" + colId + "'");
			// }
			// if ("integer".equals(colType)) { // 整型
			// sql.append(" AND T.COL_TYPE = 'integer'");
			// } else if ("float".equals(colType)) {
			// sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
			// }
			// List<Object[]> titleList =
			// this.hibernateDao.findBySQL(sql.toString());
			// if (titleList.size() > 0) {
			// for (int j = 0; j < titleList.size(); j++) {
			// // 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
			// String lookupName = tabTitle + "." + (String)
			// titleList.get(j)[0];
			// String lookupCode = tableId + "," + (String) titleList.get(j)[1];
			// colNmeStr = colNmeStr + "{lookupName:'" + lookupName +
			// "',lookupCode:'" + lookupCode + "'},";
			// }
			// }
			// colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
			// colNmeStr = colNmeStr + "]";
			// } else {
			// 根据nodeId查找tableId
			List<Map<String, Object>> tabIdList = this.getCbbTableIdsByNodeIdByIntfs(orgId, deptId, sysId, nodeId);
			if (tabIdList.size() > 0) {
				colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
				for (int i = 0; i < tabIdList.size(); i++) {
					Map<String, Object> tabIdMap = tabIdList.get(i);
					String tabId = (String) tabIdMap.get("TABLE_ID");
					// if (tabId.equals(tableId)) {
					String tabTitle = this.getTabTitleByTabId(tabId);
					// 根据tableId查找可组合字段
					StringBuffer sql = new StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tabId + "' AND T.COL_IS_DISPLAY='Y'");
					if (tableId.equals(tabId)) {
						sql.append(" AND T.ID <> '" + colId + "'");
					}
					if ("integer".equals(colType)) { // 整型
						sql.append(" AND T.COL_TYPE = 'integer'");
					} else if ("float".equals(colType)) {
						sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
					}
					List<Object[]> titleList = this.hibernateDao.findBySQL(sql.toString());
					if (titleList.size() > 0) {
						for (int j = 0; j < titleList.size(); j++) {
							// 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
							String lookupName = tabTitle + "." + (String) titleList.get(j)[0];
							String lookupCode = tabId + "," + (String) titleList.get(j)[1];
							colNmeStr = colNmeStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
						}
					}
					// }
				}
				colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
				colNmeStr = colNmeStr + "]";
			}
			// }
		} else { // 案卷级表字段
			colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
			// 根据tableId查找可组合字段
			String tabTitle = this.getTabTitleByTabId(tableId);
			StringBuffer sql = new StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tableId + "' AND T.COL_IS_DISPLAY='Y'");
			if (tableId.equals(tableId)) {
				sql.append(" AND T.ID <> '" + colId + "'");
			}
			if ("integer".equals(colType)) { // 整型
				sql.append(" AND T.COL_TYPE = 'integer'");
			} else if ("float".equals(colType)) {
				sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
			}
			List<Object[]> titleList = this.hibernateDao.findBySQL(sql.toString());
			if (titleList.size() > 0) {
				for (int j = 0; j < titleList.size(); j++) {
					// 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
					String lookupName = tabTitle + "." + (String) titleList.get(j)[0];
					String lookupCode = tableId + "," + (String) titleList.get(j)[1];
					colNmeStr = colNmeStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
				}
			}
			colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
			colNmeStr = colNmeStr + "]";
		}
		return colNmeStr;
	}

	/***
	 * 配置组合项时，构造可组合字段下拉列表(lookupName:表名.字段名,lookupCode:tableId.columnId)
	 */
	public String getColNmaeByColTypeNew(String tableId, String colType, String colId, String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 文件级非ARCHIVE_CODE字段可以组合案卷级和文件级字段，案卷级字段只能组合案卷级字段
		// 判断表类型(文件级，案卷级)
		boolean ajjFlag = checkTabIsAJJ(tableId, nodeId);// 案卷级表标识
		getColumnNameById(colId);
		String colNmeStr = "";
		if (!ajjFlag) { // 文件级表字段
			// if ("ARCHIVE_CODE".equals(colName)) { //
			// 文件级表中的ARCHIVE_CODE字段，只能组合文件级字段
			// colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
			// // 根据tableId查找可组合字段
			// String tabTitle = this.getTabTitleByTabId(tableId);
			// StringBuffer sql = new
			// StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '"
			// + tableId + "' AND T.COL_IS_DISPLAY='Y'");
			// if (tableId.equals(tableId)) {
			// sql.append(" AND T.ID <> '" + colId + "'");
			// }
			// if ("integer".equals(colType)) { // 整型
			// sql.append(" AND T.COL_TYPE = 'integer'");
			// } else if ("float".equals(colType)) {
			// sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
			// }
			// List<Object[]> titleList =
			// this.hibernateDao.findBySQL(sql.toString());
			// if (titleList.size() > 0) {
			// for (int j = 0; j < titleList.size(); j++) {
			// // 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
			// String lookupName = tabTitle + "." + (String)
			// titleList.get(j)[0];
			// String lookupCode = tableId + "," + (String) titleList.get(j)[1];
			// colNmeStr = colNmeStr + "{lookupName:'" + lookupName +
			// "',lookupCode:'" + lookupCode + "'},";
			// }
			// }
			// colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
			// colNmeStr = colNmeStr + "]";
			// } else {
			// 根据nodeId查找tableId
			List<Map<String, Object>> tabIdList = this.getCbbTableIdsByNodeIdByIntfs(orgId, deptId, sysId, nodeId);
			if (tabIdList.size() > 0) {
				colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
				for (int i = 0; i < tabIdList.size(); i++) {
					Map<String, Object> tabIdMap = tabIdList.get(i);
					String tabId = (String) tabIdMap.get("TABLE_ID");
					String tabTitle = this.getTabTitleByTabId(tabId);
					// 根据tableId查找可组合字段
					StringBuffer sql = new StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tabId + "' AND T.COL_IS_DISPLAY='Y'");
					if (tableId.equals(tabId)) {
						sql.append(" AND T.ID <> '" + colId + "'");
					}
					if ("integer".equals(colType)) { // 整型
						sql.append(" AND T.COL_TYPE = 'integer'");
					} else if ("float".equals(colType)) {
						sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
					}
					List<Object[]> titleList = this.hibernateDao.findBySQL(sql.toString());
					if (titleList.size() > 0) {
						for (int j = 0; j < titleList.size(); j++) {
							// 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
							String lookupName = tabTitle + "." + (String) titleList.get(j)[0];
							String lookupCode = tabId + "," + (String) titleList.get(j)[1];
							colNmeStr = colNmeStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
						}
					}
				}
				colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
				colNmeStr = colNmeStr + "]";
			}
			// }
		} else { // 案卷级表字段
			colNmeStr = colNmeStr + "[{lookupName:'请选择',lookupCode:''},";
			// 根据tableId查找可组合字段
			String tabTitle = this.getTabTitleByTabId(tableId);
			StringBuffer sql = new StringBuffer("SELECT T.COL_LABEL,T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tableId + "' AND T.COL_IS_DISPLAY='Y'");
			if (tableId.equals(tableId)) {
				sql.append(" AND T.ID <> '" + colId + "'");
			}
			if ("integer".equals(colType)) { // 整型
				sql.append(" AND T.COL_TYPE = 'integer'");
			} else if ("float".equals(colType)) {
				sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float')");
			}
			List<Object[]> titleList = this.hibernateDao.findBySQL(sql.toString());
			if (titleList.size() > 0) {
				for (int j = 0; j < titleList.size(); j++) {
					// 拼接json串（lookupName:表名.字段名,lookupCode:tableId.columnId）
					String lookupName = tabTitle + "." + (String) titleList.get(j)[0];
					String lookupCode = tableId + "," + (String) titleList.get(j)[1];
					colNmeStr = colNmeStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
				}
			}
			colNmeStr = colNmeStr.substring(0, colNmeStr.length() - 1);
			colNmeStr = colNmeStr + "]";
		}
		return colNmeStr;
	}

	/***
	 * 保存组合项配置信息
	 *
	 * @author 郭亮
	 * @param configColumns
	 * @param configInput
	 * @param sourceColumnId
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param orders
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void saveConfigGroup(String sourceColumnId, String[] configColumns, String[] configInput, String tableId, String orgId, String deptId, String sysId, String[] orders) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 1、先删该字段的组合项配置信息
		String sql = "DELETE FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceColumnId + "'";
		this.jdbcAvicit.getJdbcTemplate().execute(sql);
		SysLogUtil.log("库结构定义模块", "删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		// 2、保存该字段新的组合项配置信息
		// 截取tgtId
		String[] columnIds = new String[configColumns.length];
		String[] tableIds = new String[configColumns.length];
		// 根据.号从配置字符串中截取tableId和columnId
		for (int i = 0; i < configColumns.length; i++) {
			String id = configColumns[i];
			if ("".equals(id)) { // 为空
				tableIds[i] = "";
				columnIds[i] = "";
			} else {
				String[] tcId = id.split(",");
				tableIds[i] = tcId[0];
				columnIds[i] = tcId[1];
			}
		}
		// 保存
		for (int j = 0; j < columnIds.length; j++) {
			String tgtTabId = tableIds[j];
			String tgtColumnId = columnIds[j];
			if (!"".equals(tgtTabId) && !"".equals(tgtColumnId)) {
				CbbTabColConfigGroup cbbTabColConfigGroup = new CbbTabColConfigGroup();
				String id = ComUtil.getId();
				cbbTabColConfigGroup.setId(id);
				cbbTabColConfigGroup.setSourceColumnId(sourceColumnId);
				cbbTabColConfigGroup.setTargetTableId(tgtTabId);
				cbbTabColConfigGroup.setTargetColumnId(tgtColumnId);
				if (j < configInput.length) {
					cbbTabColConfigGroup.setTargetInput(configInput[j] == null ? "" : configInput[j]);
				} else {
					cbbTabColConfigGroup.setTargetInput("");
				}
				cbbTabColConfigGroup.setGroupOrder(orders[j]);
				cbbTabColConfigGroup.setSourceTableId(tableId);
				cbbTabColConfigGroup.setOrgId(orgId);
				cbbTabColConfigGroup.setDeptId(deptId);
				cbbTabColConfigGroup.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColConfigGroup, OpType.insert);
				this.hibernateDao.save(cbbTabColConfigGroup);
				SysLogUtil.log(cbbTabColConfigGroup, null, OpType.insert, OpResult.success);
			}
		}
	}

	/***
	 * 保存组合项配置信息
	 *
	 * @author 郭亮
	 * @param sourceColumnId
	 *            源字段ID
	 * @param json
	 *            组合项配置json
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @throws Exception
	 */
	@Override
	public void saveConfigGroupNew(String sourceColumnId, String json, String orgId, String deptId, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 1、先删该字段的组合项配置信息
		String sql = "DELETE FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceColumnId + "'";
		this.jdbcAvicit.getJdbcTemplate().execute(sql);
		SysLogUtil.log("库结构定义模块", "删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());

		// 2、解析json,保存该字段新的组合项配置信息
		JSONArray ja = JSONArray.fromObject(json);
		int order = 0;
		for (int i = 0; i < ja.size(); i++) {
			order++;// 顺序
			JSONObject jj = JSONObject.fromObject(ja.get(i));
			String tgtColumnId = jj.getString("0");// 组合字段
			String tgtInput = jj.getString("1");// 组合固定值
			CbbTabColConfigGroup cbbTabColConfigGroup = new CbbTabColConfigGroup();
			cbbTabColConfigGroup.setId(ComUtil.getId());
			cbbTabColConfigGroup.setSourceColumnId(sourceColumnId);// 源字段ID
			cbbTabColConfigGroup.setTargetInput(tgtInput); // 组合固定值
			cbbTabColConfigGroup.setGroupOrder(String.valueOf(order));// 组合顺序
			cbbTabColConfigGroup.setOrgId(orgId);
			cbbTabColConfigGroup.setDeptId(deptId);
			cbbTabColConfigGroup.setSysId(sysId);
			// 截取tableId和columnId
			String[] ids = tgtColumnId.split(",");
			String tgtTabId = "";
			String tgtColId = "";
			if (ids.length == 2) {
				tgtTabId = ids[0];
				tgtColId = ids[1];
			}
			cbbTabColConfigGroup.setTargetTableId(tgtTabId);// 组合字段所在表ID
			cbbTabColConfigGroup.setTargetColumnId(tgtColId);// 组合字段ID
			// 有字段或者固定值时可以保存
			if (!"".equals(tgtColumnId) || !"".equals(tgtInput)) {
				PojoUtil.setSysProperties(cbbTabColConfigGroup, OpType.insert);
				this.hibernateDao.save(cbbTabColConfigGroup);
				SysLogUtil.log(cbbTabColConfigGroup, null, OpType.insert, OpResult.success);
			}
		}
	}

	/***
	 * 根据字段名获取字段ID
	 *
	 * @author 郭亮
	 * @param id
	 * @param tableId
	 * @return String
	 * @throws
	 */
	@Override
	public String getColumnIdByName(String name, String tableId) throws Exception {
		name = name.toUpperCase(); // 将参数转换为大写
		String columnId = "";
		if (!"".equals(name)) {
			String sql = "SELECT T.ID FROM CBB_TAB_COLUMNS T WHERE T.COL_NAME = '" + name + "' AND T.TABLE_ID = '" + tableId + "'";
			List<String> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				columnId = list.get(0);
			}
		}
		return columnId;
	}

	/***
	 * 著录页面显示组合项配置信息
	 *
	 * @author 郭亮
	 * @param sourceId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	public String getCofigGroupBySourceId(String sourceId) throws Exception {
		String config = "";
		if (!"".equals(sourceId)) {
			String sql = "SELECT T.TARGET_COLUMN_ID,T.TARGET_INPUT,T.TARGET_TABLE_ID FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceId + "'";
			List<Object[]> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					String tgtColumnId = (String) list.get(i)[0];
					String tgtInput = (String) list.get(i)[1];
					String tgtTableId = (String) list.get(i)[2];
					if (!"".equals(tgtColumnId) && !"".equals(tgtTableId)) {
						String tgtColumnName = this.getColumCNNameById(tgtColumnId);
						String tgtTabName = this.getTabTitleByTabId(tgtTableId);
						if (!"".equals(tgtColumnName) && !"".equals(tgtTabName)) {
							config = config + "+" + tgtTabName + "." + tgtColumnName;
						}
					}
					if (!"".equals(tgtInput) && null != tgtInput) {
						config = config + "+\"" + tgtInput + "\"";
					}
				}
				config = config.substring(1);
			}
		}
		return config;
	}

	/***
	 * 根据字段ID获取字段中文名
	 *
	 * @author 郭亮
	 * @param id
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	public String getColumCNNameById(String id) throws Exception {
		String name = "";
		if (!"".equals(id)) {
			String sql = "SELECT T.COL_LABEL FROM CBB_TAB_COLUMNS T WHERE T.ID = '" + id + "'";
			List<String> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				name = list.get(0);
			}
		}
		return name;
	}

	/***
	 * 配置页面初始化组合项配置信息
	 *
	 * @author 郭亮
	 * @param sourceId
	 * @return
	 * @throws Exception
	 *             Map<String,Object>
	 * @throws
	 */
	@Override
	public Map<String, Object> getGroupConfig(String sourceId) throws Exception {
		Map<String, Object> groupMap = new HashMap<String, Object>();
		String sql = "SELECT T.TARGET_TABLE_ID,T.TARGET_COLUMN_ID,T.TARGET_INPUT,T.GROUP_ORDER FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceId + "'";
		List<Object[]> list = this.hibernateDao.findBySQL(sql);
		if (list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				String tgtTableId = (String) list.get(i)[0];
				String tgtColumnId = (String) list.get(i)[1];
				String select = "";
				if (!"".equals(tgtTableId) && !"".equals(tgtColumnId)) {
					select = tgtTableId + "," + tgtColumnId;
				}
				String tgtInput = (String) list.get(i)[2];
				String order = (String) list.get(i)[3];
				if ("1".equals(order)) {
					groupMap.put("1", select);
					groupMap.put("2", tgtInput);
				} else if ("2".equals(order)) {
					groupMap.put("3", select);
					groupMap.put("4", tgtInput);
				} else if ("3".equals(order)) {
					groupMap.put("5", select);
				}
			}
		}
		return groupMap;
	}

	/***
	 * 根据源字段获取组合项配置信息（配置页面初始化时使用）
	 *
	 * @author 郭亮
	 * @param sourceId
	 * @return [{
	 *         'tgtColumn':'','tgtInput':'','order':''},{'tgtColumn':'','tgtInpu
	 *         t ' : ' ' , ' o r d e r ' : ' ' } ]
	 * @throws Exception
	 */
	@Override
	public String getGroupConfigNew(String sourceId) throws Exception {
		String json = "";
		String sql = "SELECT T.TARGET_TABLE_ID,T.TARGET_COLUMN_ID,T.TARGET_INPUT,T.GROUP_ORDER FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceId + "' ORDER BY T.GROUP_ORDER";
		List<Object[]> list = this.hibernateDao.findBySQL(sql);
		if (list.size() > 0) {
			int orderFlag = 0;
			for (int i = 0; i < list.size(); i++) {
				orderFlag++;// 位置标示
				String tgtTabId = String.valueOf(list.get(i)[0]);
				String tgtColId = String.valueOf(list.get(i)[1]);
				String tgtInput = String.valueOf(list.get(i)[2]);
				String order = String.valueOf(list.get(i)[3]);
				if (orderFlag < Integer.parseInt(order)) { // 给之前的顺序位置上补空值
					for (int j = orderFlag; j < Integer.parseInt(order); j++) {
						json = json + ",{'tgtColumn':'','tgtInput':'','order':'" + j + "'}";
					}
					orderFlag = Integer.parseInt(order);// 重置位置标示
				}
				if (!"".equals(tgtTabId) && !"null".equals(tgtTabId) && !"".equals(tgtColId) && !"null".equals(tgtColId)) {
					String tgtColumn = tgtTabId + "," + tgtColId;
					json = json + ",{'tgtColumn':'" + tgtColumn + "',";
				} else {
					json = json + ",{'tgtColumn':'',";
				}
				json = json + "'tgtInput':'" + (tgtInput.equals("null") ? "" : tgtInput) + "','order':'" + order + "'}";
			}
		}
		if (!"".equals(json)) {
			json = json.substring(1);
		}
		json = "[" + json + "]";
		return json;
	}

	/**
	 * 根据节点ID，获取表IDS
	 *
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 * @author 朱锋
	 */
	public List<Map<String, Object>> getCbbTableIdsByNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listTableIds = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.TABLE_ID\n");
		sbSql.append("  FROM CBB_TAB_NODE T\n");
		sbSql.append(" WHERE T.NODE_ID = '" + nodeId + "'\n");
		sbSql.append("   AND T.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
		sbSql.append(" ORDER BY T.TAB_ORDER ASC");
		listTableIds = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listTableIds;
	}

	/***
	 * 根据表ID获取表中文名
	 *
	 * @author 郭亮
	 * @param tabId
	 * @return String
	 * @throws
	 */
	@Override
	public String getTabTitleByTabId(String tabId) throws Exception {
		String tabName = "";
		if (tabId != null && !"null".equals(tabId) && !"".equals(tabId)) {
			String sql = "SELECT T.TABLE_TITLE FROM CBB_TABLES T WHERE T.ID = '" + tabId + "'";
			List<String> tabNameList = this.hibernateDao.findBySQL(sql);
			if (tabNameList.size() > 0) {
				tabName = tabNameList.get(0);
			}
		}
		return tabName;
	}

	/***
	 * 判断索引名是否唯一
	 *
	 * @author 郭亮
	 * @param indexName
	 * @return boolean true：唯一，false：不唯一
	 * @throws
	 */
	@Override
	public boolean checkIndexNameIsUnique(String indexName, String insertData) throws Exception {
		boolean flagDb = true;
		boolean flagJsp = true;
		if (indexName != null && !"".equals(indexName) && !"null".equals(indexName)) {
			String sql = "SELECT T.ID FROM CBB_TAB_COL_INDEX T WHERE T.INDEX_NAME = '" + indexName + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			int a = list.size();
			if (a > 0) {
				flagDb = false;
			}
		}
		if (!"".equals(insertData) && !"[]".equals(insertData) && !"[{\"ID\":\"\"}]".equals(insertData)) { // 页面有未保存的添加数据
			// 获取页面indexName和构造的indenName进行对比
			JSONArray ja = JSONArray.fromObject(insertData);
			for (int i = 0; i < ja.size() - 1; i++) {
				JSONObject jj = JSONObject.fromObject(ja.get(i));
				String indexNameJsp = jj.getString("INDEX_NAME") == null ? "" : jj.getString("INDEX_NAME");// 索引名称
				if (indexNameJsp.equals(indexName)) { // 索引名重复
					flagJsp = false;
				}
			}
		}
		return flagDb && flagJsp;
	}

	/***
	 * 检测普通索引唯一性
	 *
	 * @author 郭亮
	 * @param columnId
	 * @return boolean true:唯一；false：不唯一
	 * @throws
	 */
	public boolean ckeckCommnIndexUnique(String columnId, String indexType) {
		boolean flag = true;
		if (!"".equals(columnId)) {
			String sql = "SELECT COUNT(*) FROM CBB_TAB_COL_INDEX T WHERE T.COLUMN_ID = '" + columnId + "' AND T.INDEX_TYPE = '" + indexType + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				int indexCount = Integer.parseInt(String.valueOf(list.get(0)));
				if (indexCount > 0) {
					flag = false;
				}
			}
		}
		return flag;
	}

	/***
	 * 检测父节点是否为2级节点
	 *
	 * @author 郭亮
	 * @param nodeId
	 * @return
	 */
	@Override
	public boolean checkNodeIsSecond(String nodeId) throws Exception {
		boolean flag = false;
		if (!"".equals(nodeId) && null != nodeId) {
			String sql = "SELECT COUNT(*) FROM CBB_TAB_NODE T WHERE T.NODE_ID = '" + nodeId + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				String num = String.valueOf(list.get(0));
				if ("2".equals(num)) {
					flag = true;
				} else {
					flag = false;
				}
			}
		}
		return flag;
	}

	/***
	 * 检测字段是否为案卷级表中字段
	 *
	 * @author 郭亮
	 * @param tableId
	 * @param nodeId
	 * @return
	 */
	@Override
	public boolean checkTabIsAJJ(String tableId, String nodeId) throws Exception {
		boolean flag = false;
		if (!"".equals(tableId) && null != tableId && !"".equals(nodeId) && null != nodeId) {
			String sql = "SELECT T.TAB_ORDER FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "' AND T.NODE_ID = '" + nodeId + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				String num = String.valueOf(list.get(0));
				if ("1".equals(num)) {
					flag = true;
				} else {
					flag = false;
				}
			}
		}
		return flag;
	}

	/***
	 * 根据字段Id获取字段英文名
	 *
	 * @author 郭亮
	 * @param columnId
	 * @return
	 * @throws Exception
	 */
	public String getColumnNameById(String columnId) throws Exception {
		String columnName = "";
		if (!"".equals(columnId) && null != columnId) {
			String sql = "SELECT T.COL_NAME FROM CBB_TAB_COLUMNS T WHERE T.ID = '" + columnId + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				columnName = String.valueOf(list.get(0));
			}
		}
		return columnName;
	}

	/***
	 * 查找可配置字段构造下拉列表数据（用于统计生成）
	 *
	 * @author 郭亮
	 * @param tableId
	 * @param colType
	 * @param colId
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 */
	@Override
	public String getColNameByColTypeForTJSC(String tableId, String colType, String colId, String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String colNameStr = "";
		// 根据nodeId查找文件级表ID
		String wjjTabId = getWjjTabIdByNodeId(nodeId, tableId);
		// 根据tableId查找tableTitle
		String tabTitle = getTabTitleByTabId(wjjTabId);
		// 根据字段类型在文件级表中查找可配置的字段
		StringBuffer sql = new StringBuffer("SELECT T.ID,T.COL_LABEL FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + wjjTabId + "' AND T.COL_IS_DISPLAY = 'Y'");
		if ("string".equals(colType)) { // 字符串型字段
			sql.append(" AND T.COL_TYPE <> 'date'");
		} else if ("integer".equals(colType)) {
			sql.append(" AND T.COL_TYPE = 'integer' AND T.COL_TYPE <> 'date'");
		} else if ("float".equals(colType)) {
			sql.append(" AND (T.COL_TYPE = 'integer' OR T.COL_TYPE = 'float') AND T.COL_TYPE <> 'date'");
		} else if ("date".equals(colType)) {
			sql.append(" AND T.COL_TYPE = 'date'");
		}
		List<Object[]> list = this.hibernateDao.findBySQL(sql.toString());
		if (list.size() > 0) {
			// 拼接json串
			colNameStr = colNameStr + "[{lookupName:'请选择',lookupCode:''},";
			for (int i = 0; i < list.size(); i++) {
				String columnId = String.valueOf(list.get(i)[0]);
				String columnName = String.valueOf(list.get(i)[1]);
				String lookupName = tabTitle + "." + columnName;
				String lookupCode = wjjTabId + "," + columnId;
				colNameStr = colNameStr + "{lookupName:'" + lookupName + "',lookupCode:'" + lookupCode + "'},";
			}
			colNameStr = colNameStr.substring(0, colNameStr.length() - 1);
			colNameStr = colNameStr + "]";
		} else { // 无可选择字段
			colNameStr = colNameStr + "[]";
		}
		return colNameStr;
	}

	/***
	 * 根据nodeId查找文件级表Id
	 *
	 * @author 郭亮
	 * @param nodeId
	 * @param tableId
	 * @return
	 */
	public String getWjjTabIdByNodeId(String nodeId, String tableId) {
		String wjjTabId = "";
		if (!"".equals(nodeId) && null != nodeId && !"".equals(tableId) && null != tableId) {
			String sql = "SELECT T.TABLE_ID FROM CBB_TAB_NODE T WHERE T.NODE_ID = '" + nodeId + "' AND T.TABLE_ID <> '" + tableId + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				wjjTabId = String.valueOf(list.get(0));
			}
		}
		return wjjTabId;
	}

	/***
	 * 保存统计生成配置信息
	 *
	 * @author 郭亮
	 * @param sourceColumnId
	 * @param configColumns
	 * @param configInput
	 * @param tableId
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param orders
	 * @param operation
	 * @throws Exception
	 */
	@Override
	public void saveConfigTJSC(String sourceColumnId, String[] configColumns, String[] configInput, String tableId, String orgId, String deptId, String sysId, String[] orders, String operation) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 1、先删该字段的统计生成配置信息
		String sql = "DELETE FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceColumnId + "'";
		this.jdbcAvicit.getJdbcTemplate().execute(sql);
		SysLogUtil.log("库结构定义模块", "删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());

		// 2、保存该字段新的统计生成配置信息
		// 截取tgtId
		String[] columnIds = new String[configColumns.length];
		String[] tableIds = new String[configColumns.length];
		// 根据.号从配置字符串中截取tableId和columnId
		for (int i = 0; i < configColumns.length; i++) {
			String id = configColumns[i];
			if ("".equals(id)) { // 为空
				tableIds[i] = "";
				columnIds[i] = "";
			} else {
				String[] tcId = id.split(",");
				tableIds[i] = tcId[0];
				columnIds[i] = tcId[1];
			}
		}
		// 保存
		for (int j = 0; j < columnIds.length; j++) {
			String tgtTabId = tableIds[j];
			String tgtColumnId = columnIds[j];
			if (!"".equals(tgtTabId) && !"".equals(tgtColumnId)) {
				CbbTabColConfigGroup cbbTabColConfigGroup = new CbbTabColConfigGroup();
				String id = ComUtil.getId();
				cbbTabColConfigGroup.setId(id);
				cbbTabColConfigGroup.setSourceColumnId(sourceColumnId);
				cbbTabColConfigGroup.setTargetTableId(tgtTabId);
				cbbTabColConfigGroup.setTargetColumnId(tgtColumnId);
				cbbTabColConfigGroup.setSourceTableId(tableId);// 设置源字段表ID(统计生成配置信息独有)
				cbbTabColConfigGroup.setTargetColumnOperation(operation);// 设置配置字段的运算方式(统计生成配置信息独有)
				if (j < configInput.length) {
					cbbTabColConfigGroup.setTargetInput(configInput[j] == null ? "" : configInput[j]);
				} else {
					cbbTabColConfigGroup.setTargetInput("");
				}
				cbbTabColConfigGroup.setGroupOrder(orders[j]);
				cbbTabColConfigGroup.setOrgId(orgId);
				cbbTabColConfigGroup.setDeptId(deptId);
				cbbTabColConfigGroup.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColConfigGroup, OpType.insert);
				this.hibernateDao.save(cbbTabColConfigGroup);
				SysLogUtil.log(cbbTabColConfigGroup, null, OpType.insert, OpResult.success);
			}
		}
	}

	/***
	 * 著录页面显示统计生成配置信息
	 *
	 * @author 郭亮
	 * @param sourceId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	public String getCofigTjscBySourceId(String sourceId) throws Exception {
		String config = "";
		if (!"".equals(sourceId)) {
			String sql = "SELECT T.TARGET_COLUMN_ID,T.TARGET_INPUT,T.TARGET_TABLE_ID,T.TARGET_COLUMN_OPERATION FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceId + "'";
			List<Object[]> list = this.hibernateDao.findBySQL(sql);
			String operation = "";
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					String tgtColumnId = (String) list.get(i)[0];
					String tgtInput = (String) list.get(i)[1];
					String tgtTableId = (String) list.get(i)[2];
					operation = (String) list.get(i)[3];
					if (!"".equals(tgtColumnId) && !"".equals(tgtTableId)) {
						String tgtColumnName = this.getColumCNNameById(tgtColumnId);
						if (!"".equals(tgtColumnName)) {
							config = config + "+(" + tgtColumnName + ")";
						}
					}
					if (i < 2) {
						if (!"".equals(tgtInput) && null != tgtInput) {
							config = config + "+'" + tgtInput + "'";
						}
					}
				}
				config = config.substring(1);
				// 拼接运算符
				if ("1".equals(operation)) {
					operation = "第一个";
				} else if ("2".equals(operation)) {
					operation = "最后一个";
				} else if ("3".equals(operation)) {
					operation = "最大的";
				} else if ("4".equals(operation)) {
					operation = "最小的";
				} else if ("5".equals(operation)) {
					operation = "求和";
				}
				config = operation + "{[文件级的]" + config + "}";
			}
		}
		return config;
	}

	/***
	 * 统计生成显示页面初始化获取数据
	 *
	 * @param sourceColumnId
	 * @return List<String> 0:配置字符串；1:运算方式；2：中文描述
	 * @throws Exception
	 */
	@Override
	public List<String> getTjscConfigformanager(String sourceColumnId) throws Exception {
		List<String> list = new ArrayList<String>();
		if (!"".equals(sourceColumnId) && null != sourceColumnId) {
			String sql = "SELECT T.TARGET_COLUMN_ID,T.TARGET_INPUT,T.TARGET_TABLE_ID,T.TARGET_COLUMN_OPERATION FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceColumnId + "'";
			List<Object[]> sqlList = this.hibernateDao.findBySQL(sql);
			String operation = "";
			String config = "";
			String describtion = "";
			if (sqlList.size() > 0) {
				for (int i = 0; i < sqlList.size(); i++) {
					String tgtColumnId = (String) sqlList.get(i)[0];
					String tgtInput = (String) sqlList.get(i)[1];
					// String tgtTableId = (String) sqlList.get(i)[2];
					operation = (String) sqlList.get(i)[3];
					if (!"".equals(tgtColumnId)) {
						String tgtColumnName = this.getColumCNNameById(tgtColumnId);
						if (!"".equals(tgtColumnName)) {
							config = config + "+" + tgtColumnName;
							describtion = describtion + "+(" + tgtColumnName + ")";
						}
					}
					if (i < 2) {
						if (!"".equals(tgtInput) && null != tgtInput) {
							config = config + "+'" + tgtInput + "'";
							describtion = describtion + "+'" + tgtInput + "'";
						}
					}
				}
				config = config.substring(1, config.length());
				describtion = describtion.substring(1, describtion.length());
				describtion = "{[文件级的]" + describtion + "}";
				list.add(config);
				list.add(operation);
				list.add(describtion);
			}
		}
		return list;
	}

	/***
	 * 统计生成编辑页面初始化获取配置信息
	 *
	 * @author 郭亮
	 * @param sourceId
	 * @return
	 * @throws Exception
	 *             Map<String,Object>
	 * @throws
	 */
	@Override
	public Map<String, Object> getTjscConfig(String sourceId) throws Exception {
		Map<String, Object> groupMap = new HashMap<String, Object>();
		String sql = "SELECT T.TARGET_TABLE_ID,T.TARGET_COLUMN_ID,T.TARGET_INPUT,T.GROUP_ORDER FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceId + "'";
		List<Object[]> list = this.hibernateDao.findBySQL(sql);
		if (list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				String tgtTableId = (String) list.get(i)[0];
				String tgtColumnId = (String) list.get(i)[1];
				String select = "";
				if (!"".equals(tgtTableId) && !"".equals(tgtColumnId)) {
					select = tgtTableId + "," + tgtColumnId;
				}
				String tgtInput = (String) list.get(i)[2];
				String order = (String) list.get(i)[3];
				if ("1".equals(order)) {
					groupMap.put("1", select);
					groupMap.put("2", tgtInput);
				} else if ("2".equals(order)) {
					groupMap.put("3", select);
					groupMap.put("4", tgtInput);
				} else if ("3".equals(order)) {
					groupMap.put("5", select);
				}
			}
		}
		return groupMap;
	}

	/***
	 * 删除配置信息（组合项或统计生成）
	 *
	 * @author 郭亮
	 * @param sourColumnId
	 */
	@Override
	public void deleteConfig(String sourColumnId) throws Exception {
		if (null != sourColumnId && !"".equals(sourColumnId)) {
			String sql = "DELETE FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourColumnId + "'";
			this.jdbcAvicit.getJdbcTemplate().execute(sql);
			this.jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());

		}
	}

	/**
	 * 自定义页面，根据ID查询具体的值
	 *
	 * @param code
	 * @param path
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public String getCustomValue(String value, String path) throws Exception {
		String name = "";
		if (null != path && !"".equals(path) && !"null".equals(path)) {
			String[] paths = path.split("\\?");
			if (paths.length == 2) {
				String[] param = paths[1].split("&");
				if (param.length == 3) {
					String tableName = param[0].split("=")[1];// 表名
					String columnName = param[1].split("=")[1];// 列名

					if (null != tableName && !"".equals(tableName) && !"null".equals(tableName) && null != columnName && !"".equals(columnName) && !"null".equals(columnName)) {
						StringBuffer sbSql = new StringBuffer();
						sbSql.append("SELECT " + columnName + " FROM " + tableName + " T WHERE T.ID = '" + value + "'");
						List<Object> nameList = hibernateDao.findBySQL(sbSql.toString());
						if (nameList.size() > 0) {
							name = String.valueOf(nameList.get(0));
						}
					}
				}
			}
		}
		return name;
	}

	/**
	 * 获取可配置的分类检索字段
	 *
	 * @param sysId
	 * @param orgId
	 * @param deptId
	 * @param userId
	 * @return
	 * @throws Exception
	 * @author 郭亮
	 */
	@Override
	public String getSearchCol(String sysId, String orgId, String deptId, String userId) throws Exception {
		String searchCol = "";
		// 公共字段
		// String orgCode = (String)params.get("orgCode");
		/*
		 * List<Map<String, Object>> fondsList = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, deptId, sysId, orgId); if (fondsList.size() > 0) { Map<String, Object>
		 * fondsMap = fondsList.get(0); orgCode = (String) fondsMap.get("ORG_CODE"); }
		 */
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("currentUserId", userId);
		param.put("currentDeptId", deptId);
		// param.put("currentOrgCode", orgCode);
		String tableName = "LANTOP_PUB_FIELD";
		List<Map<String, Object>> listFiled = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabNameByIntfs(orgId, deptId, sysId, tableName);
		if (listFiled.size() > 0) {
			String pubTabId = (String) listFiled.get(0).get("TABLE_ID");
			String sql = "select t.col_name from CBB_TAB_COLUMNS t where t.table_id = '" + pubTabId + "'";
			List<String> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					String colName = list.get(i);
					if ("".equals(searchCol)) {
						searchCol = colName;
					} else {
						searchCol = searchCol + "," + colName;
					}
				}
			}
		}
		// 实体表中的固定字段
		String colNamsStr = "ARCHIVE_DEPT,ARCHIVE_ACT_DATE,ARCHIVE_MANA_PERIOD,RESPONSIBLE_USER,SECRET_LEVEL";
		if ("".equals(searchCol)) {
			searchCol = colNamsStr;
		} else {
			searchCol = searchCol + "," + colNamsStr;
		}
		return searchCol;
	}

	/**
	 * 获取表层级结构类型（0:案卷，1:盒）
	 *
	 * @param nodeId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 * @author 郭亮
	 */
	@Override
	public String getTabLayerType(String nodeId) throws Exception {
		String tabLayerType = "";
		if (null == nodeId || "".equals(nodeId) || "null".equals(nodeId)) {
			throw new Exception("调用方法时nodeId参数不存在，请检查！");
		}
		String sql = "SELECT T.TAB_FLAG FROM CBB_TAB_NODE T WHERE T.NODE_ID = '" + nodeId + "'";
		List<String> list = this.hibernateDao.findBySQL(sql);
		if (list.size() > 0) {
			tabLayerType = list.get(0);
		}
		return tabLayerType;
	}

	/**
	 * 根据字段ID删除节点著录定义配置信息
	 *
	 * @param colId
	 *            字段ID
	 * @throws Exception
	 *             void
	 * @author 郭亮
	 */
	public void deleteCbbTabNodeRecordByColId(String colId) throws Exception {
		if (null == colId || "".equals(colId) || "null".equals(colId)) {
			throw new Exception("调用方法时colId参数不存在，请检查！");
		}
		String sql = "DELETE FROM CBB_TAB_NODE_RECORD T WHERE T.COLUMN_ID = '" + colId + "'";
		this.jdbcTemplate.update(sql);
	}

	/**
	 * 根据tabNodeId删除节点著录定义配置信息
	 *
	 * @param tabNodeId
	 * @throws Exception
	 *             void
	 * @author 郭亮
	 */
	@Override
	public void deleteCbbTabNodeRecordByTabNodeId(String tabNodeId) throws Exception {
		String sql = "DELETE FROM CBB_TAB_NODE_RECORD T WHERE T.TAB_NODE_ID = '" + tabNodeId + "'";
		this.jdbc.getJdbcTemplate().execute(sql);
		SysLogUtil.log("库结构定义模块", "删除节点著录定义配置信息记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 根据cbbTabColumns对象更新节点著录定义信息
	 *
	 * @param param
	 *            p1 key:sysId p2 key:orgId p3 key:deptId p4 key:tableId p5
	 *            key:obj 更新的CbbTabColumns对象
	 * @throws Exception
	 *             void
	 * @author 郭亮
	 */
	public void updateCbbTabNodeRecordByCbbColumns(Map<String, Object> param) throws Exception {
		// 1、根据tableId获取tabNodeId
		String sysId = (String) param.get("sysId");
		String orgId = (String) param.get("orgId");
		String deptId = (String) param.get("deptId");
		String tableId = (String) param.get("tableId");
		List<Object> tabNodeIdList = this.getCbbTabNodeIdByTableId(sysId, tableId, "");
		if (tabNodeIdList.size() > 0) {
			for (int i = 0; i < tabNodeIdList.size(); i++) {
				String tabNodeId = (String) tabNodeIdList.get(i);
				List<Object> configList = this.getTabNodeRecordByTabNodeId(tabNodeId);
				if (configList.size() > 0) { // 该表有配置
					CbbTabColumns cbbTabColumns = (CbbTabColumns) param.get("obj");
					// 2、判断该字段是否已存在配置信息
					List<Object> list = this.getTabNodeRecordByColId(cbbTabColumns.getId(), tabNodeId);
					if (list.size() > 0) { // 该字段有配置信息
						if ("N".equals(cbbTabColumns.getColIsDisplay())) {
							// 将字段设置为不可见，那么删除配置信息
							this.deleteCbbTabNodeRecordByColId(cbbTabColumns.getId());
						}
					} else { // 该字段无配置信息
						if ("Y".equals(cbbTabColumns.getColIsDisplay())) {
							// 将字段设置为可见，那么新增配置信息
							List<CbbTabColumns> objList = new ArrayList<CbbTabColumns>();
							objList.add(cbbTabColumns);
							this.updateCbbTabRecord(objList, sysId, tabNodeId, orgId, deptId, tableId);
						}
					}
				}
			}
		}
	}

	/**
	 * 根据字段ID，tabNodeId获取节点著录定义配置信息
	 *
	 * @param colId
	 * @return
	 * @throws Exception
	 *             List<Object>
	 * @author 郭亮
	 */
	public List<Object> getTabNodeRecordByColId(String colId, String tabNodeId) throws Exception {
		List<Object> list = new ArrayList<Object>();
		if (null == colId || "".equals(colId) || "null".equals(colId)) {
			return list;
		}
		if (null == tabNodeId || "".equals(tabNodeId) || "null".equals(tabNodeId)) {
			return list;
		}
		String sql = "SELECT * FROM CBB_TAB_NODE_RECORD T WHERE T.COLUMN_ID = '" + colId + "' AND T.TAB_NODE_ID = '" + tabNodeId + "'";
		list = this.hibernateDao.findBySQL(sql);
		return list;
	}

	/**
	 * 根据tabNodeId获取节点著录定义配置信息
	 *
	 * @param tabNodeId
	 * @return
	 * @throws Exception
	 *             List<Object>
	 * @author 郭亮
	 */
	public List<Object> getTabNodeRecordByTabNodeId(String tabNodeId) throws Exception {
		List<Object> list = new ArrayList<Object>();
		if (null == tabNodeId || "".equals(tabNodeId) || "null".equals(tabNodeId)) {
			return list;
		}
		String sql = "SELECT * FROM CBB_TAB_NODE_RECORD T WHERE T.TAB_NODE_ID = '" + tabNodeId + "'";
		list = this.hibernateDao.findBySQL(sql);
		return list;
	}

	/**
	 * 根据表ID删除组合项、统计生成配置信息
	 *
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @author 郭亮
	 */
	@Override
	public void deleteGroupConfigByTableId(String tableId) throws Exception {
		String sql = "DELETE FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_TABLE_ID = '" + tableId + "' OR T.TARGET_TABLE_ID = '" + tableId + "'";
		this.jdbcAvicit.getJdbcTemplate().execute(sql);
		this.jdbcAvicit.getJdbcTemplate().execute("commit");
		SysLogUtil.log("库结构定义模块", "删除组合项、统计生成配置信息记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 通过tableId获取formId用于表单配置信息
	 *
	 * @param sysId
	 * @param tableId
	 * @return
	 * @throws Exception
	 */
	public List<String> getFormIdByTableIdByFormConfig(String sysId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 1、根据tableId查找nodeId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.FORM_ID\n");
		sbSql.append("  FROM CBB_TAB_FORM_NODE T\n");
		sbSql.append("  LEFT JOIN CBB_TAB_NODE CTN\n");
		sbSql.append("    ON CTN.ID = T.TAB_NODE_ID\n");
		sbSql.append(" WHERE CTN.TABLE_ID = '" + tableId + "'");
		List<String> formIdLsit = this.hibernateDao.findBySQL(sbSql.toString());
		return formIdLsit;
	}

	/**
	 * @Title: getFormConfigByFormIdByTableId
	 * @Description: 根据表id和form id 查询FormConfig表信息
	 * @param sysId
	 * @param tableId
	 * @param formId
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 * @date 2019-08-20
	 * @author HuangJian
	 */
	public Map<String, Object> getformConfigByFormIdAndColId(String formId, String colId) throws Exception {
		// sysId = sysId.toUpperCase(); // 将参数转换为大写
		String sql = "SELECT * FROM CBB_TAB_FORM_CONFIG T WHERE T.FORM_ID = '" + formId + "' AND T.COLUMN_ID = '" + colId + "'";
		Map<String, Object> info = jdbcAvicit.getJdbcTemplate().queryForMap(sql);
		return info;
	}

	@Override
	public void restoreCbbTabRecordData(String tabNodeId, String tableId) throws Exception {
		// TODO Auto-generated method stub
		String sql = "DELETE FROM CBB_TAB_NODE_RECORD WHERE TAB_NODE_ID='" + tabNodeId + "' and TABLE_ID='" + tableId + "'";
		this.jdbcAvicit.getJdbcTemplate().execute(sql);
	}

	/**
	 * 新增列各种信息
	 *
	 * @param cbbTabColumnsArray
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableName
	 * @throws Exception
	 *             void
	 * @throws
	 * @author 朱锋
	 */
	@Override
	public void syntabNodeRecordData(CbbTabColumns[] cbbTabColumnsArray, String sysId, String nodeId, String nodeName, String tableName, String orgId, String deptId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("orgId", orgId);
		for (int i = 0; i < cbbTabColumnsArray.length; i++) {
			CbbTabColumns cbbTabColumns = cbbTabColumnsArray[i];
			// 实体表已经存在的情况下,新增字段都是可为空的
			if (cbbTabColumns == null) {
				throw new Exception("对象转换为cbbTabColumns对象出错！");
			}
			// 查询tableId
			String tableId = getTableIdBysysIdAndTableName(sysId, tableName, param);
			// 2同步节点著录定义配置信息
			Map<String, Object> tabNodeRecordParam = new HashMap<String, Object>();
			tabNodeRecordParam.put("sysId", sysId);
			tabNodeRecordParam.put("orgId", orgId);
			tabNodeRecordParam.put("deptId", deptId);
			tabNodeRecordParam.put("tableId", tableId);
			tabNodeRecordParam.put("obj", cbbTabColumns);
			this.updateCbbTabNodeRecordByCbbColumns(tabNodeRecordParam);
		}
	}

	/**
	 * 同步树结构和库表
	 *
	 * @param param
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void doSyncArchiveClassAndTables(Map<String, Object> param) throws Exception {
		String sourceOrgId = (String) param.get("SOURCE_ORG_ID");
		String orgCode = (String) param.get("ORG_CODE");
		String orgName = (String) param.get("ORG_NAME");
		String orgId = (String) param.get("ORG_ID");
		String userId = (String) param.get("USER_ID");
		String ip = (String) param.get("IP");
		String sysId = (String) param.get("SYS_ID");
		// long randomNum = (long)(Math.random()*1000000)+1;
		try {
			// // 获取源分类树模版数据
			// StringBuffer sourceClassSql = new StringBuffer();
			// sourceClassSql.append("SELECT * FROM LANTOP_ARCHIVE_TAB_CLASS_V\n");
			// sourceClassSql.append("WHERE TABLE_NAME = '-1' AND ORG_ID = '" +
			// sourceOrgId + "'\n");
			// sourceClassSql.append("CONNECT BY PRIOR ID = PARENT_ID\n");
			// sourceClassSql.append("START WITH PARENT_ID = 'ROOT'\n");
			// sourceClassSql.append("ORDER SIBLINGS BY NODE_SORT_NUMBER");
			// 获取源分类树模版数据，过滤不存在物理表的模版节点
			StringBuffer sourceClassSql = new StringBuffer();
			sourceClassSql.append("WITH LAC AS\n");
			sourceClassSql.append(" (SELECT *\n");
			sourceClassSql.append("    FROM LANTOP_ARCHIVE_TAB_CLASS_V\n");
			sourceClassSql.append("   WHERE TABLE_NAME = '-1'\n");
			sourceClassSql.append("     AND ORG_ID = '" + sourceOrgId + "' AND (ARCHIVE_TYPE <> '10' OR ARCHIVE_TYPE IS NULL OR ARCHIVE_TYPE = '')\n");
			sourceClassSql.append("  CONNECT BY PRIOR ID = PARENT_ID\n");
			sourceClassSql.append("   START WITH PARENT_ID = 'ROOT'\n");
			sourceClassSql.append("   ORDER SIBLINGS BY NODE_SORT_NUMBER),\n");
			sourceClassSql.append("TAB_NODE AS\n");
			sourceClassSql.append(" (SELECT CTN.NODE_ID, CT.*\n");
			sourceClassSql.append("    FROM CBB_TAB_NODE CTN\n");
			sourceClassSql.append("   INNER JOIN CBB_TABLES CT\n");
			sourceClassSql.append("      ON CT.ID = CTN.TABLE_ID\n");
			sourceClassSql.append("    LEFT JOIN LANTOP_ARCHIVE_TAB_CLASS_V T\n");
			sourceClassSql.append("      ON T.ID = CTN.NODE_ID\n");
			sourceClassSql.append("   WHERE T.TABLE_NAME = '-1'\n");
			sourceClassSql.append("     AND T.ORG_ID = '" + sourceOrgId + "'\n");
			sourceClassSql.append("     AND T.ARCHIVE_TYPE IS NOT NULL\n");
			sourceClassSql.append("     AND T.ARCHIVE_TYPE <> '0'\n");
			sourceClassSql.append("     AND T.ARCHIVE_TYPE <> '10')\n");
			sourceClassSql.append("SELECT *\n");
			sourceClassSql.append("  FROM LAC\n");
			sourceClassSql.append(" WHERE LAC.ID NOT IN\n");
			sourceClassSql.append("       (SELECT NODE_ID\n");
			sourceClassSql.append("          FROM TAB_NODE\n");
			sourceClassSql.append("         WHERE TAB_NODE.TABLE_NAME NOT IN\n");
			sourceClassSql.append("               (SELECT ALL_T.TABLE_NAME FROM ALL_TABLES ALL_T ))");

			List<Map<String, Object>> sourceClassList = this.jdbcAvicit.getJdbcTemplate().queryForList(sourceClassSql.toString());
			// 原组织分类树节点id集合
			List<String> sourceClassIdList = new ArrayList<String>();
			// 新组织分类树节点id集合
			List<String> newClassIdList = new ArrayList<String>();
			// 节点id对应map key为原组织分类树节点id，value为新组织分类树节点id
			Map<String, String> nodeMap = new HashMap<String, String>();
			// 给源分类树id集合赋值，给新分类树id集合赋值
			for (int i = 0; i < sourceClassList.size(); i++) {
				Map<String, Object> sourceClassMap = sourceClassList.get(i);
				String sourceClassId = sourceClassMap.get("ID").toString();
				String id = ComUtil.getId();
				sourceClassIdList.add(sourceClassId);
				newClassIdList.add(id);
				nodeMap.put(sourceClassId, id);
			}
			// 循环插入新组织应用分类树数据
			for (int i = 0; i < sourceClassList.size(); i++) {
				Map<String, Object> sourceClassMap = sourceClassList.get(i);
				String sourceClassId = sourceClassMap.get("ID").toString();
				LantopArchiveClass lac = this.hibernateDao.get(LantopArchiveClass.class, sourceClassId);
				String nodeCode = lac.getArchiveClassNodeCode();
				String nodeName = lac.getArchiveClassNodeName();
				if ("ROOT".equals(lac.getParentId())) {
					nodeCode = orgCode;
					nodeName = orgName;
				}
				String parentId = lac.getParentId();
				for (int j = 0; j < sourceClassIdList.size(); j++) {
					String sci = sourceClassIdList.get(j);
					String nci = newClassIdList.get(j);
					parentId = parentId.replaceAll(sci, nci);
				}
				String newPath = lac.getArchiveClassNodePath();
				for (int j = 0; j < sourceClassIdList.size(); j++) {
					String sci = sourceClassIdList.get(j);
					String nci = newClassIdList.get(j);
					newPath = newPath.replaceAll(sci, nci);
				}
				// sql执行插入新数据方法
				StringBuffer insertSql = new StringBuffer();
				insertSql.append("INSERT INTO LANTOP_ARCHIVE_CLASS");
				insertSql.append(" (SELECT ");
				insertSql.append(" '" + newClassIdList.get(i) + "', '" + orgId + "', '" + lac.getDeptId() + "', '" + lac.getSysId() + "', '" + nodeCode + "', '" + nodeName + "', '" + parentId + "',");
				insertSql.append(" ARCHIVE_TYPE, ARCHIVE_CLASS_NODE_TYPE, IS_VISIBLE, NODE_SORT_NUMBER, RELAT_WORKFLOW, TABLE_LAYER, '" + newPath + "',");
				insertSql.append(" REMARK, SECRET_LEVEL, SYS_APPLICATION_ID, '" + userId + "', sysdate, '" + userId + "', sysdate, '" + ip + "', 0,");
				insertSql.append(" ATTRIBUTE_01, ATTRIBUTE_02, ATTRIBUTE_03, ATTRIBUTE_04, ATTRIBUTE_05, ATTRIBUTE_06, ATTRIBUTE_07, ATTRIBUTE_08, ATTRIBUTE_09, ATTRIBUTE_10,");
				insertSql.append(" ATTRIBUTE_11, ATTRIBUTE_12, ATTRIBUTE_13, ATTRIBUTE_14, ATTRIBUTE_15 FROM LANTOP_ARCHIVE_CLASS WHERE ID = '" + sourceClassId + "')");

				this.jdbcAvicit.getJdbcTemplate().execute(insertSql.toString());
			}
			// 查询新组织应用对应分类树，获取分类树模版信息，创建库表数据
			StringBuffer searchTablesSql = new StringBuffer();
			searchTablesSql.append("WITH TAB_NODE AS (SELECT CTN.NODE_ID,CTN.TAB_ORDER, CT.*\n");
			searchTablesSql.append("  FROM CBB_TAB_NODE CTN\n");
			searchTablesSql.append(" INNER JOIN CBB_TABLES CT\n");
			searchTablesSql.append("    ON CT.ID = CTN.TABLE_ID\n");
			searchTablesSql.append("  LEFT JOIN LANTOP_ARCHIVE_TAB_CLASS_V T\n");
			searchTablesSql.append("    ON T.ID = CTN.NODE_ID\n");
			searchTablesSql.append(" WHERE T.TABLE_NAME = '-1'\n");
			searchTablesSql.append("   AND T.ORG_ID = '" + sourceOrgId + "'\n");
			searchTablesSql.append("   AND T.ARCHIVE_TYPE IS NOT NULL\n");
			searchTablesSql.append("   AND T.ARCHIVE_TYPE <> '0'\n");
			searchTablesSql.append("   AND T.ARCHIVE_TYPE <> '10' AND T.ARCHIVE_TYPE <> '13')\n");
			searchTablesSql.append("SELECT * FROM TAB_NODE WHERE TABLE_NAME IN (SELECT ALL_T.TABLE_NAME FROM ALL_TABLES ALL_T)\n");
			searchTablesSql.append("   ORDER BY TAB_NODE.TAB_ORDER DESC");
			List<Map<String, Object>> tableList = this.jdbcAvicit.getJdbcTemplate().queryForList(searchTablesSql.toString());
			// 原tableId集合
			List<String> sourceTablesList = new ArrayList<String>();
			// 新tableId集合
			List<String> newTablesList = new ArrayList<String>();
			// tableMap
			Map<String, String> tablesMap = new HashMap<String, String>();
			for (int i = 0; i < tableList.size(); i++) {
				Map<String, Object> tableMap = tableList.get(i);
				// 原tableId
				String sourceTableId = (String) tableMap.get("ID");
				sourceTablesList.add(sourceTableId);
				// 新tableId
				String id = ComUtil.getId();
				newTablesList.add(id);
				tablesMap.put(sourceTableId, id);
			}
			//存储新旧表名称,用于复制配置表做对应关系设置 ->key为原表的名称, value为对应新表的名称，可以直接根据原表的名称取出相对应的新表名称
			Map<String, String> tableNameMap = new HashMap<String, String>();
			for (int i = 0; i < tableList.size(); i++) {
				Map<String, Object> tableMap = tableList.get(i);
				// 原物理表名
				String oldTableName = (String) tableMap.get("TABLE_NAME");
				// 原节点id
				String oldNodeId = (String) tableMap.get("NODE_ID");
				// 新节点id
				String newClassId = nodeMap.get(oldNodeId);
				LantopArchiveClass lac = this.hibernateDao.get(LantopArchiveClass.class, newClassId);
				// 标识符
				String nodeCode = lac.getArchiveClassNodeCode();
				// 获取后缀
				int lastIndex = oldTableName.lastIndexOf("_");
				String tableNameFix = oldTableName.substring(lastIndex, oldTableName.length());
				String tableName = "";
				// 判断将要生成的物理表名是否存在
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_%" + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
				int num = getSumTableCount(tableName);
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + (num + 1) + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
				while (true) {
					// 判断数据库是否存在此表
					String hasTabSql = "SELECT COUNT(*) FROM ALL_TABLES W WHERE W.TABLE_NAME = '" + tableName + "'";
					List<Object> hasTabList = this.hibernateDao.findBySQL(hasTabSql);
					if (String.valueOf(hasTabList.get(0)).equals("0")) {
						break;
					} else {
						num++;
						tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + (num + 1) + tableNameFix.toUpperCase();
					}
				}
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + (num + 1) + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
				// 给新组织应用增加cbb_tables数据
				StringBuffer insertTablesSql = new StringBuffer();
				insertTablesSql.append("INSERT INTO CBB_TABLES "); // ,
																	// " + columnTest + "
				insertTablesSql.append(" (SELECT ");
				insertTablesSql.append(" '" + newTablesList.get(i) + "', '" + tableName + "', TABLE_TITLE, IS_VISIBLE, REMARK, '" + orgId + "', DEPT_ID, SYS_ID, SECRET_LEVEL,");
				insertTablesSql.append(" SYS_APPLICATION_ID, sysdate, '" + userId + "', sysdate, '" + userId + "', '" + ip + "', 0,");
				insertTablesSql.append(" ATTRIBUTE_01, ATTRIBUTE_02, ATTRIBUTE_03, ATTRIBUTE_04, ATTRIBUTE_05, ATTRIBUTE_06, ATTRIBUTE_07, ATTRIBUTE_08,");
				insertTablesSql.append(" ATTRIBUTE_09, ATTRIBUTE_10, ATTRIBUTE_11, ATTRIBUTE_12, ATTRIBUTE_13, ATTRIBUTE_14, ATTRIBUTE_15,");
				insertTablesSql.append(" TABLE_IS_TRUE_TABLE FROM CBB_TABLES WHERE ID = '" + tableMap.get("ID") + "')");

				this.jdbcAvicit.getJdbcTemplate().execute(insertTablesSql.toString());
				// 复制实体表
				String createTableSql = "CREATE TABLE " + tableName + " AS SELECT * FROM " + oldTableName + " WHERE 1 = 2";
				this.jdbcAvicit.getJdbcTemplate().execute(createTableSql);
				//保存原表与新表的名称和表id，后续复制对应表时，直接用旧表id或名称取对应新表的名称与表id
				tableNameMap.put(oldTableName, tableName);
			}
			StringBuffer searchTabNodeSql = new StringBuffer();
			searchTabNodeSql.append("SELECT CTN.*\n");
			searchTabNodeSql.append("  FROM CBB_TAB_NODE CTN\n");
			searchTabNodeSql.append(" INNER JOIN CBB_TABLES CT\n");
			searchTabNodeSql.append("    ON CT.ID = CTN.TABLE_ID\n");
			searchTabNodeSql.append("  LEFT JOIN LANTOP_ARCHIVE_TAB_CLASS_V T\n");
			searchTabNodeSql.append("    ON T.ID = CTN.NODE_ID\n");
			searchTabNodeSql.append(" WHERE T.TABLE_NAME = '-1'\n");
			searchTabNodeSql.append("   AND T.ORG_ID = '" + sourceOrgId + "'\n");
			searchTabNodeSql.append("   AND T.ARCHIVE_TYPE IS NOT NULL\n");
			searchTabNodeSql.append("   AND T.ARCHIVE_TYPE <> '0'\n");
			searchTabNodeSql.append("   AND T.ARCHIVE_TYPE <> '10' AND T.ARCHIVE_TYPE <> '13'");
			searchTabNodeSql.append("   ORDER BY CTN.TAB_ORDER DESC");
			List<Map<String, Object>> tabNodeList = this.jdbcAvicit.getJdbcTemplate().queryForList(searchTabNodeSql.toString());
			// 原tabNodeId集合
			List<String> sourceTabNodeList = new ArrayList<String>();
			// 新tabNodeId集合
			List<String> newTabNodeList = new ArrayList<String>();
			for (int i = 0; i < tabNodeList.size(); i++) {
				Map<String, Object> tabNodeMap = tabNodeList.get(i);
				// 原tabNodeId
				String sourceTabNodeId = (String) tabNodeMap.get("ID");
				sourceTabNodeList.add(sourceTabNodeId);
				// 新tabNodeId
				String id = ComUtil.getId();
				newTabNodeList.add(id);
			}
			for (int i = 0; i < tabNodeList.size(); i++) {
				Map<String, Object> tabNodeMap = tabNodeList.get(i);
				String tableId = (String) tabNodeMap.get("TABLE_ID");
				// 将原tableId替换为新tableId
				for (int j = 0; j < sourceTablesList.size(); j++) {
					String st = sourceTablesList.get(j);
					String nt = newTablesList.get(j);
					if (tableId.equals(st)) {
						tableId = tableId.replaceAll(st, nt);
						break;
					}
				}
				String nodeId = (String) tabNodeMap.get("NODE_ID");
				// 将原nodeId替换为新nodeId
				for (int j = 0; j < sourceClassIdList.size(); j++) {
					String sci = sourceClassIdList.get(j);
					String nci = newClassIdList.get(j);
					if (nodeId.equals(sci)) {
						nodeId = nodeId.replaceAll(sci, nci);
						break;
					}
				}
				// 给新组织应用增加cbb_tab_node数据
				StringBuffer insertTabNodeSql = new StringBuffer();
				insertTabNodeSql.append("INSERT INTO CBB_TAB_NODE ");
				insertTabNodeSql.append(" (SELECT ");
				insertTabNodeSql.append(" '" + newTabNodeList.get(i) + "', '" + tableId + "', '" + nodeId + "', TAB_ORDER, REMARK, '" + orgId + "', DEPT_ID, SYS_ID, SECRET_LEVEL, SYS_APPLICATION_ID,");
				insertTabNodeSql.append(" sysdate, '" + userId + "', sysdate, '" + userId + "', '" + ip + "', 0,ATTRIBUTE_01, ATTRIBUTE_02,");
				insertTabNodeSql.append(" ATTRIBUTE_03, ATTRIBUTE_04, ATTRIBUTE_05, ATTRIBUTE_06, ATTRIBUTE_07, ATTRIBUTE_08, ATTRIBUTE_09, ATTRIBUTE_10,");
				insertTabNodeSql.append("  ATTRIBUTE_11, ATTRIBUTE_12, ATTRIBUTE_13, ATTRIBUTE_14, ATTRIBUTE_15, TAB_FLAG FROM CBB_TAB_NODE WHERE ID = '" + tabNodeMap.get("ID") + "')");
				this.jdbcAvicit.getJdbcTemplate().execute(insertTabNodeSql.toString());
			}
			// 保存表与列的集合
			Map<String, String> columnsMap = new HashMap<String, String>();
			// 将原table关系数据复制新table关系数据
			for (int i = 0; i < sourceTablesList.size(); i++) {
				String sourceTableId = sourceTablesList.get(i);
				String newTableId = newTablesList.get(i);
				//获取表名
				String sourceTableName = getCbbTablesById(sourceTableId).getTableName();//源表名称
				String newTableName = getCbbTablesById(newTableId).getTableName();//新表名称
				// 先取原table列信息，创建给新table列信息
				String searchTabColumnSql = "SELECT * FROM CBB_TAB_COLUMNS CTC WHERE CTC.TABLE_ID = '" + sourceTableId + "'";
				List<Map<String, Object>> sourceColumnList = this.jdbcAvicit.getJdbcTemplate().queryForList(searchTabColumnSql);
				// 原组织列id集合
				List<String> sourceColumnIdList = new ArrayList<String>();
				// 新组织列id集合
				List<String> newColumnIdList = new ArrayList<String>();
				for (int j = 0; j < sourceColumnList.size(); j++) {
					Map<String, Object> sourceColumnMap = sourceColumnList.get(j);
					String sourceColumnId = (String) sourceColumnMap.get("ID");
					String id = ComUtil.getId();
					sourceColumnIdList.add(sourceColumnId);
					newColumnIdList.add(id);
					columnsMap.put(sourceColumnId, id);
				}
				for (int j = 0; j < sourceColumnList.size(); j++) {
					Map<String, Object> sourceColumnMap = sourceColumnList.get(j);
					StringBuffer insertColumnSql = new StringBuffer();
					insertColumnSql.append("INSERT INTO CBB_TAB_COLUMNS ");
					insertColumnSql.append(" (SELECT ");
					insertColumnSql.append(" '" + newColumnIdList.get(j) + "', '" + newTableId + "', COL_NAME, COL_LABEL, COL_TYPE, COL_LENGTH, COL_DECIMAL, COL_IS_SYS, COL_ORDER, COL_IS_MUST, COL_IS_VISIBLE,");
					insertColumnSql.append(" COL_IS_SEARCH, COL_IS_EDIT, COL_IS_TAB_VISIBLE, COL_IS_DETAIL, COL_DROPDOWN_TYPE, COL_GENE_METHOD, COL_RULE_NAME,");
					insertColumnSql.append(" COL_RULE_TITLE,CUSTOM_PATH, REMARK, '" + orgId + "', DEPT_ID, SYS_ID, SECRET_LEVEL, SYS_APPLICATION_ID, sysdate,");
					insertColumnSql.append(" '" + userId + "', sysdate, '" + userId + "', '" + ip + "', 0, ATTRIBUTE_01, ATTRIBUTE_02, ATTRIBUTE_03, ATTRIBUTE_04,");
					insertColumnSql.append(" ATTRIBUTE_05, ATTRIBUTE_06, ATTRIBUTE_07, ATTRIBUTE_08, ATTRIBUTE_09, ATTRIBUTE_10, ATTRIBUTE_11, ATTRIBUTE_12, ATTRIBUTE_13,");
					insertColumnSql.append(" ATTRIBUTE_14, ATTRIBUTE_15, COL_SHOW_FORMAT, COL_GENE_METHOD_RULE, COL_IS_DISPLAY, COL_IS_COMPLEMENT, COL_COMPLEMENT_NUM ,COL_GENE_METHOD_RULE_TEXT FROM CBB_TAB_COLUMNS WHERE ID = '" + sourceColumnMap.get("ID") + "')");
					this.jdbcAvicit.getJdbcTemplate().execute(insertColumnSql.toString());
				}
				//更新列著录规则
				//判断该表属于一层库表还是二层库表
				StringBuffer sbSqltabNode = new StringBuffer();
				sbSqltabNode.append("SELECT TTT.TABLE_ID,TTT.TAB_FLAG\n");
				sbSqltabNode.append("  FROM CBB_TAB_NODE TTT\n");
				sbSqltabNode.append(" WHERE TTT.NODE_ID IN\n");
				sbSqltabNode.append("       (SELECT CTN.NODE_ID\n");
				sbSqltabNode.append("          FROM CBB_TAB_NODE CTN\n");
				sbSqltabNode.append("          LEFT JOIN LANTOP_ARCHIVE_CLASS LAC\n");
				sbSqltabNode.append("            ON LAC.ID = CTN.NODE_ID\n");
				sbSqltabNode.append("         WHERE CTN.TABLE_ID = '" + sourceTableId + "'\n");
				sbSqltabNode.append("           AND LAC.ARCHIVE_TYPE IS NOT NULL\n");
				sbSqltabNode.append("           AND LAC.ARCHIVE_CLASS_NODE_TYPE IS NULL)");
				List<Map<String, Object>> sbSqltabNodeList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqltabNode.toString());
				if(sbSqltabNodeList.size() == 1){
					//如果是一级库表
					//1、顺带
					//获取规则值
					StringBuffer sbSqlSdq = new StringBuffer();
					sbSqlSdq.append("SELECT T.ID,T.COL_GENE_METHOD_RULE\n");
					sbSqlSdq.append("  FROM CBB_TAB_COLUMNS T\n");
					sbSqlSdq.append(" WHERE T.TABLE_ID = '" + newTableId + "'\n");
					sbSqlSdq.append("   AND T.COL_GENE_METHOD = '3'");
					List<Map<String, Object>> sbSqlSdqList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlSdq.toString());
					for (int j = 0; j < sbSqlSdqList.size(); j++) {
						String colId = String.valueOf(sbSqlSdqList.get(j).get("ID"));//列ID
						String colGeneMethodRule = String.valueOf(sbSqlSdqList.get(j).get("COL_GENE_METHOD_RULE"));//规则具体值
						String colGeneMethodRuleColId = colGeneMethodRule.split(",")[1];//获取规则中的列ID
						String ncolId = columnsMap.get(colGeneMethodRuleColId);//新列ID
						StringBuffer sbSqlSd = new StringBuffer();
						sbSqlSd.append("UPDATE CBB_TAB_COLUMNS T\n");
						sbSqlSd.append("   SET T.COL_GENE_METHOD_RULE = '" + newTableId + "," + ncolId + "'\n");
						sbSqlSd.append(" WHERE T.ID = '" + colId + "'\n");
						sbSqlSd.append("   AND T.COL_GENE_METHOD = '3'");
						this.jdbcAvicit.getJdbcTemplate().execute(sbSqlSd.toString());
					}
					//2、组合项
					StringBuffer sbSqlZhxq = new StringBuffer();
					sbSqlZhxq.append("SELECT T.ID,T.COL_GENE_METHOD_RULE\n");
					sbSqlZhxq.append("  FROM CBB_TAB_COLUMNS T\n");
					sbSqlZhxq.append(" WHERE T.TABLE_ID = '" + newTableId + "'\n");
					sbSqlZhxq.append("   AND T.COL_GENE_METHOD = '4'");
					List<Map<String, Object>> sbSqlZhxqList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlZhxq.toString());
					for (int j = 0; j < sbSqlZhxqList.size(); j++) {
						String colId = String.valueOf(sbSqlZhxqList.get(j).get("ID"));//列ID
						String colGeneMethodRule = String.valueOf(sbSqlZhxqList.get(j).get("COL_GENE_METHOD_RULE"));//规则具体值
						colGeneMethodRule = colGeneMethodRule.replaceAll(sourceTableName, newTableName);
						StringBuffer sbSqlZhx = new StringBuffer();
						sbSqlZhx.append("UPDATE CBB_TAB_COLUMNS T\n");
						sbSqlZhx.append("   SET T.COL_GENE_METHOD_RULE = '" + colGeneMethodRule + "'\n");
						sbSqlZhx.append(" WHERE T.ID = '" + colId + "'\n");
						sbSqlZhx.append("   AND T.COL_GENE_METHOD = '4'");
						this.jdbcAvicit.getJdbcTemplate().execute(sbSqlZhx.toString());
					}
				}else{
					//如果是二级库表
					//获取新表对应关系
					StringBuffer sbSqltabNodeNew = new StringBuffer();
					sbSqltabNodeNew.append("SELECT TTT.TABLE_ID,TTT.TAB_FLAG\n");
					sbSqltabNodeNew.append("  FROM CBB_TAB_NODE TTT\n");
					sbSqltabNodeNew.append(" WHERE TTT.NODE_ID IN\n");
					sbSqltabNodeNew.append("       (SELECT CTN.NODE_ID\n");
					sbSqltabNodeNew.append("          FROM CBB_TAB_NODE CTN\n");
					sbSqltabNodeNew.append("          LEFT JOIN LANTOP_ARCHIVE_CLASS LAC\n");
					sbSqltabNodeNew.append("            ON LAC.ID = CTN.NODE_ID\n");
					sbSqltabNodeNew.append("         WHERE CTN.TABLE_ID = '" + newTableId + "'\n");
					sbSqltabNodeNew.append("           AND LAC.ARCHIVE_TYPE IS NOT NULL\n");
					sbSqltabNodeNew.append("           AND LAC.ARCHIVE_CLASS_NODE_TYPE IS NULL)");
					sbSqltabNodeNew.append("    AND TTT.TABLE_ID <> '" + newTableId + "'");
					List<Map<String, Object>> sbSqltabNodeNewList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqltabNodeNew.toString());
					String tableIdNew = String.valueOf(sbSqltabNodeNewList.get(0).get("TABLE_ID"));
					String tableIdNewName = getCbbTablesById(tableIdNew).getTableName();//兄弟表新表名称
					//旧表对应关系
					StringBuffer sbSqltabNodeOld = new StringBuffer();
					sbSqltabNodeOld.append("SELECT TTT.TABLE_ID,TTT.TAB_FLAG\n");
					sbSqltabNodeOld.append("  FROM CBB_TAB_NODE TTT\n");
					sbSqltabNodeOld.append(" WHERE TTT.NODE_ID IN\n");
					sbSqltabNodeOld.append("       (SELECT CTN.NODE_ID\n");
					sbSqltabNodeOld.append("          FROM CBB_TAB_NODE CTN\n");
					sbSqltabNodeOld.append("          LEFT JOIN LANTOP_ARCHIVE_CLASS LAC\n");
					sbSqltabNodeOld.append("            ON LAC.ID = CTN.NODE_ID\n");
					sbSqltabNodeOld.append("         WHERE CTN.TABLE_ID = '" + sourceTableId + "'\n");
					sbSqltabNodeOld.append("           AND LAC.ARCHIVE_TYPE IS NOT NULL\n");
					sbSqltabNodeOld.append("           AND LAC.ARCHIVE_CLASS_NODE_TYPE IS NULL)");
					sbSqltabNodeOld.append("    AND TTT.TABLE_ID <> '" + sourceTableId + "'");
					List<Map<String, Object>> sbSqltabNodeOldList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqltabNodeOld.toString());
					String tableIdOld = String.valueOf(sbSqltabNodeOldList.get(0).get("TABLE_ID"));
					String tableIdOldName = getCbbTablesById(tableIdOld).getTableName();//兄弟表新表名称
					//整理新旧表对应关系
					Map<String,String> tableIdsle = new HashMap<String,String>();//表ID对应关系
					tableIdsle.put(sourceTableId, newTableId);
					tableIdsle.put(tableIdOld, tableIdNew);//兄弟表对应关系
					Map<String,String> tableNamesle = new HashMap<String,String>();//表名对应关系
					tableNamesle.put(sourceTableName, newTableName);
					tableNamesle.put(tableIdOldName, tableIdNewName);//兄弟表对应关系
					//1、顺带
					//获取规则值
					StringBuffer sbSqlSdq = new StringBuffer();
					sbSqlSdq.append("SELECT T.ID,T.COL_GENE_METHOD_RULE\n");
					sbSqlSdq.append("  FROM CBB_TAB_COLUMNS T\n");
					sbSqlSdq.append(" WHERE T.TABLE_ID = '" + newTableId + "'\n");
					sbSqlSdq.append("   AND T.COL_GENE_METHOD = '3'");
					List<Map<String, Object>> sbSqlSdqList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlSdq.toString());
					for (int j = 0; j < sbSqlSdqList.size(); j++) {
						String colId = String.valueOf(sbSqlSdqList.get(j).get("ID"));//列ID
						String colGeneMethodRule = String.valueOf(sbSqlSdqList.get(j).get("COL_GENE_METHOD_RULE"));//规则具体值
						String colGeneMethodRuleTableId = colGeneMethodRule.split(",")[0];//获取规则中的列表ID
						String colGeneMethodRuleColId = colGeneMethodRule.split(",")[1];//获取规则中的列ID
						String ncolId = columnsMap.get(colGeneMethodRuleColId);//新列ID
						String newcolGeneMethodRule = tableIdsle.get(colGeneMethodRuleTableId) + "," + ncolId;
						StringBuffer sbSqlSd = new StringBuffer();
						sbSqlSd.append("UPDATE CBB_TAB_COLUMNS T\n");
						sbSqlSd.append("   SET T.COL_GENE_METHOD_RULE = '" + newcolGeneMethodRule + "'\n");
						sbSqlSd.append(" WHERE T.ID = '" + colId + "'\n");
						sbSqlSd.append("   AND T.COL_GENE_METHOD = '3'");
						this.jdbcAvicit.getJdbcTemplate().execute(sbSqlSd.toString());
					}
					//2、组合项
					StringBuffer sbSqlZhxq = new StringBuffer();
					sbSqlZhxq.append("SELECT T.ID,T.COL_GENE_METHOD_RULE\n");
					sbSqlZhxq.append("  FROM CBB_TAB_COLUMNS T\n");
					sbSqlZhxq.append(" WHERE T.TABLE_ID = '" + newTableId + "'\n");
					sbSqlZhxq.append("   AND T.COL_GENE_METHOD = '4'");
					List<Map<String, Object>> sbSqlZhxqList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlZhxq.toString());
					for (int j = 0; j < sbSqlZhxqList.size(); j++) {
						String colId = String.valueOf(sbSqlZhxqList.get(j).get("ID"));//列ID
						String colGeneMethodRule = String.valueOf(sbSqlZhxqList.get(j).get("COL_GENE_METHOD_RULE"));//规则具体值
						colGeneMethodRule = colGeneMethodRule.replaceAll(sourceTableName, newTableName);
						colGeneMethodRule = colGeneMethodRule.replaceAll(tableIdOldName, tableIdNewName);
						colGeneMethodRule = colGeneMethodRule.replaceAll("'", "''");
						StringBuffer sbSqlZhx = new StringBuffer();
						sbSqlZhx.append("UPDATE CBB_TAB_COLUMNS T\n");
						sbSqlZhx.append("   SET T.COL_GENE_METHOD_RULE = '" + colGeneMethodRule + "'\n");
						sbSqlZhx.append(" WHERE T.ID = '" + colId + "'\n");
						sbSqlZhx.append("   AND T.COL_GENE_METHOD = '4'");
						this.jdbcAvicit.getJdbcTemplate().execute(sbSqlZhx.toString());
					}
					// 复制CBB_TAB_COL_CONFIG_GROUP数据
					StringBuffer sbtjscSqlq = new StringBuffer();
					sbtjscSqlq.append("SELECT *\n");
					sbtjscSqlq.append("  FROM CBB_TAB_COL_CONFIG_GROUP\n");
					sbtjscSqlq.append(" WHERE SOURCE_TABLE_ID = '" + sourceTableId + "'");
					List<Map<String, Object>> sbtjscSqlqList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbtjscSqlq.toString());
					for (int j = 0; j < sbtjscSqlqList.size(); j++) {
						String sourceColId = String.valueOf(sbtjscSqlqList.get(j).get("SOURCE_COLUMN_ID"));//原源表列ID
						String tacrgetColId = String.valueOf(sbtjscSqlqList.get(j).get("TARGET_COLUMN_ID"));//原目标表列ID
						String tacrgetInput = String.valueOf(sbtjscSqlqList.get(j).get("TARGET_INPUT"));//组合输入值
						String deptId = String.valueOf(sbtjscSqlqList.get(j).get("DEPT_ID"));//部门ID
						String secretLevel = String.valueOf(sbtjscSqlqList.get(j).get("SECRET_LEVEL"));//密级
						String sysApplicationId = String.valueOf(sbtjscSqlqList.get(j).get("SYS_APPLICATION_ID"));//SYS_APPLICATION_ID
						String groupOrder = String.valueOf(sbtjscSqlqList.get(j).get("GROUP_ORDER"));//GROUP_ORDER
						String targetColumnOperation = String.valueOf(sbtjscSqlqList.get(j).get("TARGET_COLUMN_OPERATION"));//运算方式
						StringBuffer sbcolIdSql = new StringBuffer();
						sbcolIdSql.append("SELECT CTC.ID\n");
						sbcolIdSql.append("  FROM CBB_TAB_COLUMNS CTC\n");
						sbcolIdSql.append(" WHERE CTC.COL_NAME =\n");
						sbcolIdSql.append("       (SELECT C.COL_NAME FROM CBB_TAB_COLUMNS C WHERE C.ID = '" + tacrgetColId + "')\n");
						sbcolIdSql.append("   AND CTC.TABLE_ID = '" + tableIdNew + "'");
						List<Map<String, Object>> sbcolIdSqlList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbcolIdSql.toString());
						if(sbcolIdSqlList.size() == 1){
							String newtacrgetColId = String.valueOf(sbcolIdSqlList.get(0).get("ID"));//原源表列ID
							StringBuffer sbtjscSql = new StringBuffer();
							sbtjscSql.append("INSERT INTO CBB_TAB_COL_CONFIG_GROUP VALUES (\n");
							sbtjscSql.append("          sys_guid(),\n");
							sbtjscSql.append("          '" + columnsMap.get(sourceColId) + "',\n");
							sbtjscSql.append("          '" + newtacrgetColId + "',\n");
							if(null == tacrgetInput || "null".equals(tacrgetInput)){
								tacrgetInput = "";
							}
							sbtjscSql.append("          '" + tacrgetInput + "',\n");
							sbtjscSql.append("          '" + orgId + "',\n");
							sbtjscSql.append("          '" + deptId + "',\n");
							sbtjscSql.append("          '" + sysId + "',\n");
							if(null == secretLevel || "null".equals(secretLevel)){
								secretLevel = "";
							}
							sbtjscSql.append("          '" + secretLevel + "',\n");
							if(null == sysApplicationId || "null".equals(sysApplicationId)){
								sysApplicationId = "";
							}
							sbtjscSql.append("          '" + sysApplicationId + "',\n");
							sbtjscSql.append("          sysdate,\n");
							sbtjscSql.append("          '" + userId + "',\n");
							sbtjscSql.append("          sysdate,\n");
							sbtjscSql.append("          '" + userId + "',\n");
							sbtjscSql.append("          '" + ip + "',\n");
							sbtjscSql.append("          0,\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          '',\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          NULL,\n");
							sbtjscSql.append("          '" + groupOrder + "',\n");
							sbtjscSql.append("          '" + tableIdNew + "',\n");
							sbtjscSql.append("          '" + newTableId + "',\n");
							sbtjscSql.append("          '" + targetColumnOperation + "')\n");
							this.jdbcAvicit.getJdbcTemplate().execute(sbtjscSql.toString());
						}
					}
				}
			}
			// 复制CBB_TAB_FORM_NODE数据
			List<String> sourceTabFormIdList = new ArrayList<String>();
			List<String> newTabFormIdList = new ArrayList<String>();
			for (int i = 0; i < sourceTabNodeList.size(); i++) {
				String searchTabFormNodeHql = "from CbbTabFormNode where tabNodeId = '" + sourceTabNodeList.get(i) + "'";
				List<CbbTabFormNode> tabFormNodeList = this.hibernateDao.find(searchTabFormNodeHql);
				for (int j = 0; j < tabFormNodeList.size(); j++) {
					CbbTabFormNode ctfn = tabFormNodeList.get(j);
					String oldTabFormId = ctfn.getFormId();
					// 获取原tabForm数据
					CbbTabForm ctf = this.hibernateDao.get(CbbTabForm.class, oldTabFormId);
					// 创建新tabForm数据
					String ctfId = ComUtil.getId();
					this.hibernateDao.evict(ctf);
					ctf.setCreationDate(new Date());
					ctf.setOrgId(orgId);
					ctf.setId(ctfId);
					this.hibernateDao.save(ctf);
					newTabFormIdList.add(ctfId);
					// 创建新tabFormNode数据
					String ctfnId = ComUtil.getId();
					this.hibernateDao.evict(ctfn);
					ctfn.setCreationDate(new Date());
					ctfn.setOrgId(orgId);
					ctfn.setTabNodeId(newTabNodeList.get(i));
					ctfn.setFormId(ctf.getId());
					ctfn.setId(ctfnId);
					this.hibernateDao.save(ctfn);
					sourceTabFormIdList.add(oldTabFormId);
				}
			}
			// 复制CBB_TAB_FORM_CONFIG数据
			for (int i = 0; i < sourceTabFormIdList.size(); i++) {
				// 获取原tabFormConfig数据
				List<CbbTabFormConfig> ctcList = this.hibernateDao.find("from CbbTabFormConfig where formId = '" + sourceTabFormIdList.get(i) + "'");
				for (int j = 0; j < ctcList.size(); j++) {
					CbbTabFormConfig ctc = ctcList.get(j);
					// 创建新CBB_TAB_FORM_CONFIG数据
					String ctcId = ComUtil.getId();
					this.hibernateDao.evict(ctc);
					ctc.setCreationDate(new Date());
					ctc.setOrgId(orgId);
					if (null == columnsMap.get(ctc.getColumnId())) {
						continue;
					}
					ctc.setColumnId(columnsMap.get(ctc.getColumnId()));
					ctc.setFormId(newTabFormIdList.get(i));
					ctc.setId(ctcId);
					this.hibernateDao.save(ctc);
				}
			}
			// 根据原tableId查询插入CBB_TAB_COL_SYS_CODE、CBB_TAB_COL_CODE、CBB_TAB_COL_INDEX、CBB_TAB_COL_SEARCH、CBB_TAB_COL_SORT数据
			Map<String, String> colSysCodeMap = new HashMap<String, String>();
			for (int i = 0; i < sourceTablesList.size(); i++) {
				String sourceTableId = sourceTablesList.get(i);
				// 插入CBB_TAB_COL_SYS_CODE
				String ctcscSql = "SELECT * FROM CBB_TAB_COL_SYS_CODE WHERE TABLE_ID = '" + sourceTableId + "'";
				List<Map<String, Object>> ctcscList = this.jdbcAvicit.getJdbcTemplate().queryForList(ctcscSql);
				for (int j = 0; j < ctcscList.size(); j++) {
					Map<String, Object> ctcscMap = ctcscList.get(j);
					String oldId = (String) ctcscMap.get("ID");
					CbbTabColSysCode ctcsc = this.hibernateDao.get(CbbTabColSysCode.class, oldId);
					String ctcscId = ComUtil.getId();
					// 保存对应code数据，key为原codeId，value为新codeId
					colSysCodeMap.put(oldId, ctcscId);
					this.hibernateDao.evict(ctcsc);
					ctcsc.setCreationDate(new Date());
					ctcsc.setOrgId(orgId);
					// 排除垃圾数据，如果对应tableId或者colunmId不存在，则视为垃圾数据
					if (null == tablesMap.get(ctcsc.getTableId()) || null == columnsMap.get(ctcsc.getColumnId())) {
						continue;
					}
					ctcsc.setTableId(tablesMap.get(ctcsc.getTableId()));
					ctcsc.setColumnId(columnsMap.get(ctcsc.getColumnId()));
					ctcsc.setId(ctcscId);
					this.hibernateDao.save(ctcsc);
				}
				// 插入CBB_TAB_COL_CODE
				String ctccSql = "SELECT * FROM CBB_TAB_COL_CODE WHERE TABLE_ID = '" + sourceTableId + "'";
				List<Map<String, Object>> ctccList = this.jdbcAvicit.getJdbcTemplate().queryForList(ctccSql);
				for (int j = 0; j < ctccList.size(); j++) {
					Map<String, Object> ctccMap = ctccList.get(j);
					String oldId = (String) ctccMap.get("ID");
					CbbTabColCode ctcc = this.hibernateDao.get(CbbTabColCode.class, oldId);
					String ctccId = ComUtil.getId();
					this.hibernateDao.evict(ctcc);
					ctcc.setCreationDate(new Date());
					ctcc.setOrgId(orgId);
					// 排除垃圾数据，如果对应tableId或者colunmId不存在，则视为垃圾数据
					if (null == tablesMap.get(ctcc.getTableId()) || null == columnsMap.get(ctcc.getColumnId())) {
						continue;
					}
					ctcc.setTableId(tablesMap.get(ctcc.getTableId()));
					ctcc.setColumnId(columnsMap.get(ctcc.getColumnId()));
					ctcc.setId(ctccId);
					this.hibernateDao.save(ctcc);
				}
				// 插入CBB_TAB_COL_INDEX
				String ctciSql = "SELECT * FROM CBB_TAB_COL_INDEX WHERE TABLE_ID = '" + sourceTableId + "'";
				List<Map<String, Object>> ctciList = this.jdbcAvicit.getJdbcTemplate().queryForList(ctciSql);
				for (int j = 0; j < ctciList.size(); j++) {
					Map<String, Object> ctciMap = ctciList.get(j);
					String oldId = (String) ctciMap.get("ID");
					CbbTabColIndex ctci = this.hibernateDao.get(CbbTabColIndex.class, oldId);
					String ctciId = ComUtil.getId();
					this.hibernateDao.evict(ctci);
					ctci.setCreationDate(new Date());
					ctci.setOrgId(orgId);
					// 排除垃圾数据，如果对应tableId或者colunmId不存在，则视为垃圾数据
					if (null == tablesMap.get(ctci.getTableId()) || null == columnsMap.get(ctci.getColumnId())) {
						continue;
					}
					ctci.setTableId(tablesMap.get(ctci.getTableId()));
					ctci.setColumnId(columnsMap.get(ctci.getColumnId()));
					ctci.setId(ctciId);
					this.hibernateDao.save(ctci);
				}
				// 插入CBB_TAB_COL_SEARCH
				String ctcsSql = "SELECT * FROM CBB_TAB_COL_SEARCH WHERE TABLE_ID = '" + sourceTableId + "'";
				List<Map<String, Object>> ctcsList = this.jdbcAvicit.getJdbcTemplate().queryForList(ctcsSql);
				for (int j = 0; j < ctcsList.size(); j++) {
					Map<String, Object> ctcsMap = ctcsList.get(j);
					String oldId = (String) ctcsMap.get("ID");
					CbbTabColSearch ctcs = this.hibernateDao.get(CbbTabColSearch.class, oldId);
					String ctcsId = ComUtil.getId();
					this.hibernateDao.evict(ctcs);
					ctcs.setCreationDate(new Date());
					ctcs.setOrgId(orgId);
					// 排除垃圾数据，如果对应tableId或者colunmId不存在，则视为垃圾数据
					if (null == tablesMap.get(ctcs.getTableId()) || null == columnsMap.get(ctcs.getColumnId())) {
						continue;
					}
					ctcs.setTableId(tablesMap.get(ctcs.getTableId()));
					ctcs.setColumnId(columnsMap.get(ctcs.getColumnId()));
					ctcs.setId(ctcsId);
					this.hibernateDao.save(ctcs);
				}
				// 插入CBB_TAB_COL_SORT
				String ctcsrSql = "SELECT * FROM CBB_TAB_COL_SORT WHERE TABLE_ID = '" + sourceTableId + "'";
				List<Map<String, Object>> ctcsrList = this.jdbcAvicit.getJdbcTemplate().queryForList(ctcsrSql);
				for (int j = 0; j < ctcsrList.size(); j++) {
					Map<String, Object> ctcsrMap = ctcsrList.get(j);
					String oldId = (String) ctcsrMap.get("ID");
					CbbTabColSort ctcsr = this.hibernateDao.get(CbbTabColSort.class, oldId);
					String ctcsrId = ComUtil.getId();
					this.hibernateDao.evict(ctcsr);
					ctcsr.setCreationDate(new Date());
					ctcsr.setOrgId(orgId);
					// 排除垃圾数据，如果对应tableId或者colunmId不存在，则视为垃圾数据
					if (null == tablesMap.get(ctcsr.getTableId()) || null == columnsMap.get(ctcsr.getColumnId())) {
						continue;
					}
					ctcsr.setTableId(tablesMap.get(ctcsr.getTableId()));
					ctcsr.setColumnId(columnsMap.get(ctcsr.getColumnId()));
					ctcsr.setId(ctcsrId);
					this.hibernateDao.save(ctcsr);
				}
			}
			// 插入CBB_TAB_COL_CODE_TL
			StringBuffer searchCtcctSql = new StringBuffer();
			searchCtcctSql.append("SELECT *\n");
			searchCtcctSql.append("  FROM CBB_TAB_COL_CODE_TL CTCCT\n");
			searchCtcctSql.append(" WHERE EXISTS (SELECT *\n");
			searchCtcctSql.append("          FROM CBB_TAB_COL_CODE CTCC\n");
			searchCtcctSql.append("         WHERE EXISTS (SELECT *\n");
			searchCtcctSql.append("                  FROM CBB_TAB_COLUMNS CTC\n");
			searchCtcctSql.append("                 WHERE EXISTS (SELECT CT.ID\n");
			searchCtcctSql.append("                          FROM CBB_TAB_NODE CTN\n");
			searchCtcctSql.append("                         INNER JOIN CBB_TABLES CT\n");
			searchCtcctSql.append("                            ON CT.ID = CTN.TABLE_ID\n");
			searchCtcctSql.append("                          LEFT JOIN LANTOP_ARCHIVE_TAB_CLASS_V T\n");
			searchCtcctSql.append("                            ON T.ID = CTN.NODE_ID\n");
			searchCtcctSql.append("                         WHERE T.TABLE_NAME = '-1'\n");
			searchCtcctSql.append("                           AND T.ORG_ID = '" + sourceOrgId + "'\n");
			searchCtcctSql.append("                           AND T.ARCHIVE_TYPE IS NOT NULL\n");
			searchCtcctSql.append("                           AND T.ARCHIVE_TYPE <> '0'\n");
			searchCtcctSql.append("                           AND T.ARCHIVE_TYPE <> '10'\n");
			searchCtcctSql.append("                           AND CT.ID = CTC.TABLE_ID)\n");
			searchCtcctSql.append("                   AND CTCC.COLUMN_ID = CTC.ID)\n");
			searchCtcctSql.append("           AND CTCC.ID = CTCCT.CBB_TAB_COL_CODE_ID)");
			List<Map<String, Object>> ctcctList = this.jdbcAvicit.getJdbcTemplate().queryForList(searchCtcctSql.toString());
			for (int i = 0; i < ctcctList.size(); i++) {
				Map<String, Object> ctcctMap = ctcctList.get(i);
				CbbTabColCodeTlDTO ctcct = this.cbbTabColCodeTlService.queryCbbTabColCodeTlByPrimaryKey(ctcctMap.get("ID").toString());
				ctcct.setCbbTabColCodeId(columnsMap.get(ctcct.getCbbTabColCodeId()));
				this.cbbTabColCodeTlService.insertCbbTabColCodeTl(ctcct);
			}
			// 插入CBB_TAB_COLUMNS_TL
			StringBuffer searchCtctSql = new StringBuffer();
			searchCtctSql.append("SELECT *\n");
			searchCtctSql.append("  FROM CBB_TAB_COLUMNS_TL CTCT\n");
			searchCtctSql.append(" WHERE EXISTS (SELECT *\n");
			searchCtctSql.append("          FROM CBB_TAB_COLUMNS CTC\n");
			searchCtctSql.append("         WHERE EXISTS (SELECT CT.ID\n");
			searchCtctSql.append("                  FROM CBB_TAB_NODE CTN\n");
			searchCtctSql.append("                 INNER JOIN CBB_TABLES CT\n");
			searchCtctSql.append("                    ON CT.ID = CTN.TABLE_ID\n");
			searchCtctSql.append("                  LEFT JOIN LANTOP_ARCHIVE_TAB_CLASS_V T\n");
			searchCtctSql.append("                    ON T.ID = CTN.NODE_ID\n");
			searchCtctSql.append("                 WHERE T.TABLE_NAME = '-1'\n");
			searchCtctSql.append("                   AND T.ORG_ID = '" + sourceOrgId + "'\n");
			searchCtctSql.append("                   AND T.ARCHIVE_TYPE IS NOT NULL\n");
			searchCtctSql.append("                   AND T.ARCHIVE_TYPE <> '0'\n");
			searchCtctSql.append("                   AND T.ARCHIVE_TYPE <> '10'\n");
			searchCtctSql.append("                   AND CT.ID = CTC.TABLE_ID)\n");
			searchCtctSql.append("           AND CTC.ID = CTCT.CBB_TAB_COLUMNS_ID)");
			List<Map<String, Object>> ctctList = this.jdbcAvicit.getJdbcTemplate().queryForList(searchCtctSql.toString());
			for (int i = 0; i < ctctList.size(); i++) {
				Map<String, Object> ctctMap = ctctList.get(i);
				CbbTabColumnsTlDTO ctct = this.cbbTabColumnsTlService.queryCbbTabColumnsTlByPrimaryKey(ctctMap.get("ID").toString());
				ctct.setCbbTabColumnsId(columnsMap.get(ctct.getCbbTabColumnsId()));
				this.cbbTabColumnsTlService.insertCbbTabColumnsTl(ctct);
			}
			/*// 插入CBB_TAB_COL_CONFIG_GROUP
			StringBuffer searchCtccgSql = new StringBuffer();
			searchCtccgSql.append("SELECT *\n");
			searchCtccgSql.append("  FROM CBB_TAB_COL_CONFIG_GROUP CTCCG\n");
			searchCtccgSql.append(" WHERE EXISTS (SELECT *\n");
			searchCtccgSql.append("          FROM CBB_TAB_COLUMNS CTC\n");
			searchCtccgSql.append("         WHERE EXISTS (SELECT CT.ID\n");
			searchCtccgSql.append("                  FROM CBB_TAB_NODE CTN\n");
			searchCtccgSql.append("                 INNER JOIN CBB_TABLES CT\n");
			searchCtccgSql.append("                    ON CT.ID = CTN.TABLE_ID\n");
			searchCtccgSql.append("                  LEFT JOIN LANTOP_ARCHIVE_TAB_CLASS_V T\n");
			searchCtccgSql.append("                    ON T.ID = CTN.NODE_ID\n");
			searchCtccgSql.append("                 WHERE T.TABLE_NAME = '-1'\n");
			searchCtccgSql.append("                   AND T.ORG_ID = '" + sourceOrgId + "'\n");
			searchCtccgSql.append("                   AND T.ARCHIVE_TYPE IS NOT NULL\n");
			searchCtccgSql.append("                   AND T.ARCHIVE_TYPE <> '0'\n");
			searchCtccgSql.append("                   AND T.ARCHIVE_TYPE <> '10'\n");
			searchCtccgSql.append("                   AND CT.ID = CTC.TABLE_ID)\n");
			searchCtccgSql.append("           AND CTC.ID = CTCCG.SOURCE_COLUMN_ID)");
			List<Map<String, Object>> ctccgList = this.jdbcAvicit.getJdbcTemplate().queryForList(searchCtccgSql.toString());
			for (int i = 0; i < ctccgList.size(); i++) {
				Map<String, Object> ctccgMap = ctccgList.get(i);
				CbbTabColConfigGroup ctccg = this.hibernateDao.get(CbbTabColConfigGroup.class, ctccgMap.get("ID").toString());
				String ctccgId = ComUtil.getId();
				this.hibernateDao.evict(ctccg);
				// 排除垃圾数据，如果对应tableId或者colunmId不存在，则视为垃圾数据
				if (null == columnsMap.get(ctccg.getSourceColumnId()) || null == columnsMap.get(ctccg.getTargetColumnId()) || null == tablesMap.get(ctccg.getTargetTableId())) {
					continue;
				}
				ctccg.setSourceColumnId(columnsMap.get(ctccg.getSourceColumnId()));
				ctccg.setTargetColumnId(columnsMap.get(ctccg.getTargetColumnId()));
				ctccg.setOrgId(orgId);
				ctccg.setCreationDate(new Date());
				ctccg.setSourceTableId(tablesMap.get(ctccg.getSourceTableId()));
				ctccg.setTargetTableId(tablesMap.get(ctccg.getTargetTableId()));
				ctccg.setId(ctccgId);
				this.hibernateDao.save(ctccg);
			}*/
			//复制字段对应设置信息
			//查找上级组织字段对于设置信息    本组织库表对应信息+本组织库表与公共字段对应信息
			StringBuffer sbSqlfrs = new StringBuffer();
			sbSqlfrs.append("SELECT *\n");
			sbSqlfrs.append("  FROM LANTOP_FIELD_RELATE_SET T\n");
			sbSqlfrs.append(" WHERE T.TGT_ARCHIVE_CLASS_ID IS NULL\n");
			sbSqlfrs.append("   AND T.ORG_ID = '" + sourceOrgId + "'\n");
			sbSqlfrs.append("   AND T.SOURCE_TABLE_ID NOT IN\n");
			sbSqlfrs.append("       (SELECT CT.ID\n");
			sbSqlfrs.append("          FROM CBB_TABLES CT\n");
			sbSqlfrs.append("         WHERE CT.ORG_ID <> '" + sourceOrgId + "')\n");
			sbSqlfrs.append("   AND T.TGT_TABLE_ID NOT IN\n");
			sbSqlfrs.append("       (SELECT CT.ID\n");
			sbSqlfrs.append("          FROM CBB_TABLES CT\n");
			sbSqlfrs.append("         WHERE CT.ORG_ID <> '" + sourceOrgId + "')\n");
			sbSqlfrs.append("UNION ALL\n");
			sbSqlfrs.append("SELECT *\n");
			sbSqlfrs.append("  FROM LANTOP_FIELD_RELATE_SET T\n");
			sbSqlfrs.append(" WHERE T.TGT_TABLE_NAME = 'LANTOP_PUB_FIELD'\n");
			sbSqlfrs.append("   AND T.SOURCE_TABLE_ID IN\n");
			sbSqlfrs.append("       (SELECT CT.ID\n");
			sbSqlfrs.append("          FROM CBB_TABLES CT\n");
			sbSqlfrs.append("         WHERE CT.ORG_ID = '" + sourceOrgId + "')");
			List<Map<String, Object>> setList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlfrs.toString());
			for (int i = 0; i < setList.size(); i++) {
				//保存字段对应设置信息表
				Map<String, Object> setMap = setList.get(i);
				String sourceId = setMap.get("ID").toString();
				//若为公共字段表，则直接复制原数据
				String oldTgtTableName = setMap.get("TGT_TABLE_NAME").toString();
				String newTgtTableName = "LANTOP_PUB_FIELD".equals(oldTgtTableName) ? oldTgtTableName : tableNameMap.get(oldTgtTableName);
				String oldTgtTableId = setMap.get("TGT_TABLE_ID").toString();
				String newTgtTableId = "LANTOP_PUB_FIELD".equals(oldTgtTableName) ? oldTgtTableId : tablesMap.get(oldTgtTableId);
				//封装对象
				LantopFieldRelateSet fieldRelateSet = this.hibernateDao.get(LantopFieldRelateSet.class, sourceId);
				String newSetId = ComUtil.getId();
				this.hibernateDao.evict(fieldRelateSet);
				fieldRelateSet.setId(newSetId);
				fieldRelateSet.setOrgId(orgId);
				fieldRelateSet.setSourceTableId(tablesMap.get(setMap.get("SOURCE_TABLE_ID").toString()));
				fieldRelateSet.setSourceTableName(tableNameMap.get(setMap.get("SOURCE_TABLE_NAME").toString()));
				fieldRelateSet.setTgtTableId(newTgtTableId);
				fieldRelateSet.setTgtTableName(newTgtTableName);
				fieldRelateSet.setCreationDate(new Date());
				if (fieldRelateSet.getSourceTableId()==null || fieldRelateSet.getSourceTableName()==null ||fieldRelateSet.getTgtTableId()==null || fieldRelateSet.getTgtTableName()==null){
					continue;
				}
				this.hibernateDao.save(fieldRelateSet);
				//保存字段对应设置明细表
				StringBuffer sbSqlfrsItem = new StringBuffer();
				sbSqlfrsItem.append("SELECT *\n");
				sbSqlfrsItem.append("  FROM LANTOP_FIELD_RELATE_SET_ITEM T\n");
				sbSqlfrsItem.append(" WHERE T.ORG_ID = '" + sourceOrgId + "'\n");
				sbSqlfrsItem.append("   AND T.LANTOP_FIELD_RELATE_SET_ID = '" + sourceId + "'\n");
				List<Map<String, Object>> setItemList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlfrsItem.toString());
				for (int j = 0; j < setItemList.size(); j++) {
					Map<String, Object> setItemMap = setItemList.get(j);
					LantopFieldRelateSetItem fieldRelateSetItem = this.hibernateDao.get(LantopFieldRelateSetItem.class, setItemMap.get("ID").toString());
					String newSetItemId = ComUtil.getId();
					this.hibernateDao.evict(fieldRelateSetItem);
					fieldRelateSetItem.setId(newSetItemId);
					fieldRelateSetItem.setOrgId(orgId);
					fieldRelateSetItem.setLantopFieldRelateSetId(newSetId);
					fieldRelateSetItem.setCreationDate(new Date());
					this.hibernateDao.save(fieldRelateSetItem);
				}
			}
			// 调用存储过程更新或建立大视图
			ArrayList<Object> params = new ArrayList<Object>();
			params.add(0, orgId);
			String tempOrgCode = orgCode;
			if (orgCode.length() > 16) {
				tempOrgCode = orgCode.substring(orgCode.length() - 16);
			}
			params.add(1, tempOrgCode);
			lantopFieldMapSetManagerDao.callProcedure("LANTOP_DATA_P.LANTOP_DATA_V", params);
			//复制菜单授权信息
			copyMuenForRole(sourceOrgId,orgId);
			//更新右上角菜单图标code
			updateTopRightMuenCode(orgId,orgCode);
			//复制数据库连接表cbb_fonds_db
			StringBuffer sbSqlCbbfdb = new StringBuffer();
			sbSqlCbbfdb.append("SELECT *\n");
			sbSqlCbbfdb.append("  FROM cbb_fonds_db T\n");
			sbSqlCbbfdb.append(" WHERE T.ORG_ID = '" + sourceOrgId + "'\n");
			List<Map<String, Object>> cbbfdbList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSqlCbbfdb.toString());
			if(cbbfdbList.size() > 0){
				Map<String, Object> cbbfdbMap = cbbfdbList.get(0);
				CbbFondsDb cbbFondsDb = this.hibernateDao.get(CbbFondsDb.class, cbbfdbMap.get("ID").toString());
				cbbFondsDb.setId(ComUtil.getId());
				cbbFondsDb.setOrgId(orgId);
				cbbFondsDb.setFondsDeptId(orgId);
				cbbFondsDb.setCreationDate(new Date());
				hibernateDao.evict(cbbFondsDb);
				this.hibernateDao.save(cbbFondsDb);
			}
			// // 删除CBB_TAB_NODE新增临时字段
			// String delTabNodeSql = "ALTER TABLE CBB_TAB_NODE DROP (" +
			// columnTest + ")";
			// this.jdbcAvicit.getJdbcTemplate().execute(delTabNodeSql);
			// // 删除CBB_TABLES新增临时字段
			// String delTableSql = "ALTER TABLE CBB_TABLES DROP (" + columnTest
			// + ")";
			// this.jdbcAvicit.getJdbcTemplate().execute(delTableSql);
			// // 删除LANTOP_ARCHIVE_CLASS新增临时字段
			// String delArchiveClassSql =
			// "ALTER TABLE LANTOP_ARCHIVE_CLASS DROP (" + columnTest + ")";
			// this.jdbcAvicit.getJdbcTemplate().execute(delArchiveClassSql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	//更新右上角菜单图标code  zms
	private void updateTopRightMuenCode(String orgId,String orgCode){
		//修改我的收藏
		String scHql = " from SysMenu t where t.orgIdentity = '"+orgId+"' and t.id in ( select tl.sysMenuId from SysMenuTl tl where tl.name = '我的收藏') ";
		List<avicit.platform6.modules.system.sysmenu.domain.SysMenu> scList = hibernateDao.find(scHql);
		if(scList != null && scList.size() > 0){
			for (avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu:scList) {
				sysMenu.setCode(orgCode+"_mysave");
				hibernateDao.update(sysMenu);
			}
		}
        //修改借阅车
		String jyHql = "SELECT * FROM SYS_MENU t WHERE t.ORG_IDENTITY = '"+orgId+"' AND t.ID IN ( SELECT tl.SYS_MENU_ID FROM SYS_MENU_TL tl WHERE tl.NAME = '借阅车' ) ";
		List<Map<String, Object>> mapList = jdbcTemplate.queryForList(jyHql);
		if(mapList != null&&mapList.size()>0){
			List<avicit.platform6.modules.system.sysmenu.domain.SysMenu> jyList = new ArrayList<>();
			for (Map<String, Object> map : mapList) {
				avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu1 = hibernateDao.get(avicit.platform6.modules.system.sysmenu.domain.SysMenu.class, map.get("ID").toString());
				jyList.add(sysMenu1);
			}
			if(jyList.size()>0) {
				for (avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu:jyList) {
					sysMenu.setCode(orgCode + "_myborrowcar");
					hibernateDao.update(sysMenu);
				}
			}
		}
		//修改我的待办
		String dbHql = "SELECT * FROM SYS_MENU t WHERE t.ORG_IDENTITY = '"+orgId+"' AND t.ID IN ( SELECT tl.SYS_MENU_ID FROM SYS_MENU_TL tl WHERE tl.NAME = '我的待办' ) ";
		List<Map<String, Object>> mapList1 = jdbcTemplate.queryForList(dbHql);
		if(mapList1 != null&&mapList1.size()>0){
			List<avicit.platform6.modules.system.sysmenu.domain.SysMenu> dbList = new ArrayList<>();
			for (Map<String, Object> map : mapList1) {
				avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu1 = hibernateDao.get(avicit.platform6.modules.system.sysmenu.domain.SysMenu.class, map.get("ID").toString());
				dbList.add(sysMenu1);
			}
			if(dbList.size()>0) {
				for (avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu:dbList) {
					sysMenu.setCode(orgCode + "_mypending");
					hibernateDao.update(sysMenu);
				}
			}
		}

		//修改我的消息
		String xxHql = "SELECT * FROM SYS_MENU t WHERE t.ORG_IDENTITY = '"+orgId+"' AND t.ID IN ( SELECT tl.SYS_MENU_ID FROM SYS_MENU_TL tl WHERE tl.NAME = '我的消息' ) ";
		List<Map<String, Object>> mapList2 = jdbcTemplate.queryForList(xxHql);
		if(mapList2 != null&&mapList2.size()>0){
			List<avicit.platform6.modules.system.sysmenu.domain.SysMenu> xxList = new ArrayList<>();
			for (Map<String, Object> map : mapList2) {
				avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu2 = hibernateDao.get(avicit.platform6.modules.system.sysmenu.domain.SysMenu.class, map.get("ID").toString());
				xxList.add(sysMenu2);
			}
			if(xxList.size()>0) {
				for (avicit.platform6.modules.system.sysmenu.domain.SysMenu sysMenu:xxList) {
					sysMenu.setCode(orgCode + "_mymessage");
					hibernateDao.update(sysMenu);
				}
			}
		}
	}

	//复制菜单授权信息  zms
	private void copyMuenForRole(String sourceOrgId ,String orgId ){
        String srSql = " select t.ID as ID,t.PARENT_ID as PARENT_ID,tl.NAME as NAME from SYS_MENU t,SYS_MENU_TL tl where t.ID = tl.SYS_MENU_ID and t.ORG_IDENTITY = '"+orgId+"' ";
        Map<String,String> sysMenuMap = new HashMap<String,String>();
		Map<String,String> menuMap = new HashMap<String,String>();
        List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(srSql);
        for (Map<String, Object> m:list) {
            sysMenuMap.put(String.valueOf(m.get("NAME") ),String.valueOf(m.get("ID"))+","+String.valueOf(m.get("PARENT_ID")));
        }


		/*8a58ab4d4c207cca014c207ffff7034c  系统管理员
		40288a46384feb2101384fef8ba80005 安全管理员
		40288a46384feb2101384ff0efc20006  安全审计员*/



		//sysResources = new ArrayList<>();
        //List<avicit.platform6.modules.system.sysmenu.domain.SysMenu> sysMenu = new ArrayList<>();
		String srHql = " from SysResource t where t.orgIdentity = '"+sourceOrgId+"'";
        List<avicit.platform6.modules.system.centralizedauthorization.domain.SysResource> sysResources = hibernateDao.find(srHql);
		String saHql = " from SysAccesscontrol t where t.orgIdentity = '"+sourceOrgId+"' and t.targetType = 'R' ";
		List<SysAccesscontrol> sysAccesscontrols = hibernateDao.find(saHql);
		String srSHql = " from SysRole t where t.orgIdentity = '"+sourceOrgId+"' ";
		String srBHql = " from SysRole t where t.orgIdentity = '"+orgId+"' ";
		List<SysRole> SysRoleSs =  hibernateDao.find(srSHql);
		List<SysRole> SysRoleBs =  hibernateDao.find(srBHql);
        for (avicit.platform6.modules.system.centralizedauthorization.domain.SysResource sysResource:sysResources) {
            String ids = sysMenuMap.get(sysResource.getKey());
            if(StringUtils.isNotBlank(ids)){
				String[] sysMenuIds = ids.split(",");
				menuMap.put(String.valueOf(sysResource.getId()),String.valueOf(sysMenuIds[0]));
				/*SysResource resource = new SysResource();
                BeanUtils.copyProperties(sysResource, resource);
				resource.setId(sysMenuIds[0]);
				resource.setParentId(sysMenuIds[1]);
				resource.setOrgIdentity(orgId);
				hibernateDao.save(resource);*/
			}
        }
		//Map<String,String> sysRoleSMap = new HashMap<String,String>();
		Map<String,String> sysRoleBMap = new HashMap<String,String>();
		Map<String,String> sysRoleMap = new HashMap<String,String>();
		for (SysRole sysRole:SysRoleBs) {
			String code = sysRole.getRoleCode();
			String[] codes = code.split("_");
			String key = "";
			for(int i = 0;i<codes.length;i++){
				if(i!=0){
					key += codes[i];
				}
			}
			sysRoleBMap.put(key,sysRole.getId());
		}
		for (SysRole sysRole:SysRoleSs) {
			String code = sysRole.getRoleCode();
			String[] codes = code.split("_");
			String key = "";
			for(int i = 0;i<codes.length;i++){
				if(i!=0){
					key += codes[i];
				}
			}
			sysRoleMap.put(sysRole.getId(),sysRoleBMap.get(key));
		}

		for (SysAccesscontrol sysAccesscontrol:sysAccesscontrols) {
			SysAccesscontrol accesscontrol = new SysAccesscontrol();
			BeanUtils.copyProperties(sysAccesscontrol, accesscontrol);
			accesscontrol.setId(ComUtil.getId());
			accesscontrol.setTargetId(sysRoleMap.get(sysAccesscontrol.getTargetId()));
			accesscontrol.setResoureId(menuMap.get(sysAccesscontrol.getResoureId()));
			accesscontrol.setOrgIdentity(orgId);
			if(accesscontrol.getTargetId()!=null){
				hibernateDao.save(accesscontrol);
			}
		}



		/*List<SysAccesscontrol> lists = new ArrayList<>();

		String srSql1 = " select t.ID as ID,t.PARENT_ID as PARENT_ID,tl.NAME as NAME from SYS_MENU t,SYS_MENU_TL tl where t.ID = tl.SYS_MENU_ID and t.ORG_IDENTITY = '"+orgId+"' ";

		//系统管理 	安全审计员
		List<Map<String, Object>> mapList = jdbc.getJdbcTemplate().queryForList("SELECT * FROM (" + srSql1 + ") WHERE NAME IN ('系统管理','系统安全管理','日志与审计')");
		if (mapList!=null&&mapList.size()>0){
			for (Map<String, Object> map : mapList) {
				SysAccesscontrol sysAccesscontrol = new SysAccesscontrol();
				sysAccesscontrol.setId(ComUtil.getId());
				sysAccesscontrol.setTargetId("40288a46384feb2101384ff0efc20006");
				sysAccesscontrol.setResoureId(map.get("ID").toString());
				sysAccesscontrol.setOrgIdentity(orgId);
				lists.add(sysAccesscontrol);
			}
		}
		//系统管理 	安全管理员
		List<Map<String, Object>> mapList1 = jdbc.getJdbcTemplate().queryForList("SELECT * FROM (" + srSql1 + ") WHERE NAME IN ('系统管理','组织机构管理','用户管理','群组管理','角色管理','授权管理','菜单授权管理','集中授权管理','系统安全管理','日志与审计','密码模版配置','IP限制管理')");
		if (mapList1!=null&&mapList1.size()>0){
			for (Map<String, Object> map : mapList1) {
				SysAccesscontrol sysAccesscontrol = new SysAccesscontrol();
				sysAccesscontrol.setId(ComUtil.getId());
				sysAccesscontrol.setTargetId("40288a46384feb2101384fef8ba80005");
				sysAccesscontrol.setResoureId(map.get("ID").toString());
				sysAccesscontrol.setOrgIdentity(orgId);
				lists.add(sysAccesscontrol);
			}
		}

		//系统管理 	系统管理员
		List<Map<String, Object>> mapList2 = jdbc.getJdbcTemplate().queryForList("SELECT * FROM (" + srSql1 + ") WHERE NAME IN ('系统管理','组织机构管理','组织管理','部门用户管理','岗位管理','用户管理'\n" +
				",'系统配置管理','菜单管理','系统参数配置','通用代码管理','在线用户','缓存管理','定时任务管理'\n" +
				",'业务流程管理','流程设计器','流程目录管理','流程表单管理','流程模版配置','流程实例监控','流程维度分析')");
		if (mapList2!=null&&mapList2.size()>0){
			for (Map<String, Object> map : mapList2) {
				SysAccesscontrol sysAccesscontrol = new SysAccesscontrol();
				sysAccesscontrol.setId(ComUtil.getId());
				sysAccesscontrol.setTargetId("8a58ab4d4c207cca014c207ffff7034c");
				sysAccesscontrol.setResoureId(map.get("ID").toString());
				sysAccesscontrol.setOrgIdentity(orgId);
				lists.add(sysAccesscontrol);
			}
		}

		for (SysAccesscontrol sysAccesscontrol : lists) {
			sysAccesscontrol.setTargetType("R");
			sysAccesscontrol.setAccessibility(1L);
			sysAccesscontrol.setOperability(1L);
			sysAccesscontrol.setSysApplicationId("1");
			sysAccesscontrol.setLastUpdateDate(new Date(System.currentTimeMillis()));
			sysAccesscontrol.setLastUpdatedBy("1");
			sysAccesscontrol.setCreatedBy("1");
			sysAccesscontrol.setCreationDate(new Date(System.currentTimeMillis()));
			sysAccesscontrol.setLastUpdateIp("127.0.0.1");
			sysAccesscontrol.setVersion(1L);
			sysAccesscontrol.setOrgIdentity(orgId);
			if(sysAccesscontrol.getTargetId()!=null){
				hibernateDao.save(sysAccesscontrol);
			}
		}*/
	}

	/**
	 * 清理组织下所有库表数据
	 *
	 * @param param
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void deleteCommTableManagerDatasByOrgId(Map<String, Object> param) throws Exception {
		String orgId = (String) param.get("ORG_ID");
		// 清理LANTOP_ARCHIVE_CLASS数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM LANTOP_ARCHIVE_CLASS LAC WHERE ORG_ID = '" + orgId + "'");
		// 对应组织应用所有物理表
		List<Map<String, Object>> tableList = this.jdbcAvicit.getJdbcTemplate().queryForList("SELECT * FROM CBB_TABLES WHERE ORG_ID = '" + orgId + "'");
		for (int i = 0; i < tableList.size(); i++) {
			Map<String, Object> tableMap = tableList.get(i);
			String tableName = (String) tableMap.get("TABLE_NAME");
			List<Map<String, Object>> isExistList = this.jdbcAvicit.getJdbcTemplate().queryForList("SELECT * FROM USER_TABLES WHERE TABLE_NAME = '" + tableName + "'");
			if (isExistList.size() > 0) {
				this.jdbcAvicit.getJdbcTemplate().execute("DROP TABLE " + tableName);
			}
		}
		// 清理CBB_TABLES数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TABLES CT WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_NODE数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_NODE CTN WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COLUMNS数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COLUMNS CTC WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_FORM_NODE数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_FORM_NODE WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_FORM数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_FORM WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_FORM_CONFIG数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_FORM_CONFIG WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_CODE数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_CODE WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_SYS_CODE数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_SYS_CODE WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_CONFIG_GROUP数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_CONFIG_GROUP WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_INDEX数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_INDEX WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_SEARCH数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_SEARCH WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_SORT数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_SORT WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_FORM数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_FORM WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_FORM_CONFIG数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_FORM_CONFIG WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_FORM_NODE数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_FORM_NODE WHERE ORG_ID = '" + orgId + "'");
		// 清理CBB_TAB_COL_CODE_TL数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COL_CODE_TL CTCCT WHERE NOT EXISTS (SELECT 1 FROM CBB_TAB_COL_CODE CTCC WHERE CTCC.ID = CTCCT.CBB_TAB_COL_CODE_ID)");
		// 清理CBB_TAB_COLUMNS_TL数据
		this.jdbcAvicit.getJdbcTemplate().execute("DELETE FROM CBB_TAB_COLUMNS_TL CTCT WHERE NOT EXISTS (SELECT 1 FROM CBB_TAB_COLUMNS CTC WHERE CTC.ID = CTCT.CBB_TAB_COLUMNS_ID)");
	}


	/**
	 * @Description: 删除相关联的组合项配置
	 * @author youyu
	 * @date 2019-9-4 下午2:40:28
	 * @param cbbTabColumns
	 * @param tableName
	 * @version 1.0
	 */
	private void deleteCombinationByCbbTabColumn(CbbTabColumns cbbTabColumns,String tableName){
		String tableId = cbbTabColumns.getTableId();//表Id
		String colName = cbbTabColumns.getColName();//字段英文名
		String colId = cbbTabColumns.getId();//字段ID

		//根据表ID获得表的所有字段信息
		String hql = "from CbbTabColumns where tableId = '" + tableId + "'";
		List<CbbTabColumns> cbbTabColumnsList = this.hibernateDao
				.find(hql);
		for(CbbTabColumns tabColums:cbbTabColumnsList){
			if(tabColums.getId().equals(colId)){//排除要删除的列
				continue;
			}
			String colGeneMethodRule = tabColums.getColGeneMethodRule();
			if(null != colGeneMethodRule && !"".equals(colGeneMethodRule) && !"null".equals(colGeneMethodRule)){
				//判断其他列组合项设置是否包含要删除的列
				if(colGeneMethodRule.indexOf(tableName.toUpperCase()+'.'+colName.toUpperCase())>-1){
					//如果存在，则置组合项列为null，更新字段信息
					tabColums.setColGeneMethodRule(null);
					tabColums.setColGeneMethodRuleText(null);
					this.hibernateDao.update(tabColums);
				}
			}
		}

	}
}
